結果
| 問題 | No.905 Sorted? | 
| コンテスト | |
| ユーザー |  tenten | 
| 提出日時 | 2022-10-06 11:09:38 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 484 ms / 2,000 ms | 
| コード長 | 1,942 bytes | 
| コンパイル時間 | 2,626 ms | 
| コンパイル使用メモリ | 80,564 KB | 
| 実行使用メモリ | 54,460 KB | 
| 最終ジャッジ日時 | 2025-01-02 20:43:59 | 
| 合計ジャッジ時間 | 10,759 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        long prev = sc.nextLong();
        int[] acc = new int[n];
        int[] dec = new int[n];
        for (int i = 1; i < n; i++) {
            long x = sc.nextLong();
            if (prev <= x) {
                acc[i] = acc[i - 1] + 1;
            } else {
                acc[i] = 0;
            }
            if (prev >= x) {
                dec[i] = dec[i - 1] + 1;
            } else {
                dec[i] = 0;
            }
            prev = x;
        }
        int q = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        while (q-- > 0) {
            int left = sc.nextInt();
            int right = sc.nextInt();
            if (acc[right] - acc[left] == right - left) {
                sb.append("1 ");
            } else {
                sb.append("0 ");
            }
            if (dec[right] - dec[left] == right - left) {
                sb.append("1\n");
            } else {
                sb.append("0\n");
            }
        }
        System.out.print(sb);
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
            
            
            
        