結果

問題 No.905 Sorted?
ユーザー tentententen
提出日時 2022-08-04 08:30:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 419 ms / 2,000 ms
コード長 1,844 bytes
コンパイル時間 2,480 ms
コンパイル使用メモリ 74,056 KB
実行使用メモリ 64,408 KB
最終ジャッジ日時 2023-10-12 05:07:55
合計ジャッジ時間 9,493 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
49,344 KB
testcase_01 AC 47 ms
49,252 KB
testcase_02 AC 47 ms
49,496 KB
testcase_03 AC 48 ms
49,232 KB
testcase_04 AC 47 ms
49,280 KB
testcase_05 AC 98 ms
52,728 KB
testcase_06 AC 80 ms
51,872 KB
testcase_07 AC 122 ms
52,428 KB
testcase_08 AC 414 ms
61,004 KB
testcase_09 AC 315 ms
57,428 KB
testcase_10 AC 401 ms
60,184 KB
testcase_11 AC 379 ms
59,612 KB
testcase_12 AC 389 ms
57,660 KB
testcase_13 AC 419 ms
64,408 KB
testcase_14 AC 416 ms
63,440 KB
testcase_15 AC 357 ms
58,376 KB
testcase_16 AC 388 ms
60,752 KB
testcase_17 AC 402 ms
59,336 KB
testcase_18 AC 363 ms
57,664 KB
testcase_19 AC 44 ms
49,356 KB
testcase_20 AC 48 ms
49,320 KB
testcase_21 AC 48 ms
49,340 KB
testcase_22 AC 46 ms
49,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
        int[] ups = new int[n];
        int[] downs = new int[n];
        long prev = sc.nextLong();
        for (int i = 1; i < n; i++) {
            ups[i] = ups[i - 1];
            downs[i] = downs[i - 1];
            long x = sc.nextLong();
            if (prev <= x) {
                ups[i]++;
            }
            if (prev >= x) {
                downs[i]++;
            }
            prev = x;
        }
        int q = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        while (q-- > 0) {
            int left = sc.nextInt();
            int right = sc.nextInt();
            if (ups[right] - ups[left] == right - left) {
                sb.append("1 ");
            } else {
                sb.append("0 ");
            }
            if (downs[right] - downs[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("");
    
    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();
    }
}
0