結果
| 問題 |
No.905 Sorted?
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-24 15:21:02 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 954 bytes |
| コンパイル時間 | 2,484 ms |
| コンパイル使用メモリ | 76,916 KB |
| 実行使用メモリ | 71,916 KB |
| 最終ジャッジ日時 | 2024-10-03 05:53:12 |
| 合計ジャッジ時間 | 20,049 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 23 |
ソースコード
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long[] a = new long[n];
for(int i = 0; i < n; i++) a[i] = sc.nextLong();
int[] gt = new int[n]; gt[0] = 0;
int[] lt = new int[n]; lt[0] = 0;
for(int i = 1; i < n; i++){
if(a[i-1] <= a[i]) gt[i] = 1;
if(a[i-1] >= a[i]) lt[i] = 1;
gt[i] += gt[i-1];
lt[i] += lt[i-1];
}
int q = sc.nextInt();
for(int i = 0; i < q; i++){
int l = sc.nextInt();
int r = sc.nextInt();
boolean asc = (gt[r]-gt[l] == r-l);
boolean dec = (lt[r]-lt[l] == r-l);
int ans = 2;
if(asc && dec) ans = 0;
else if(asc) ans = 1;
else if(dec) ans = -1;
System.out.println(ans);
}
}
}