結果

問題 No.905 Sorted?
ユーザー tentententen
提出日時 2020-08-27 09:48:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 995 ms / 2,000 ms
コード長 1,271 bytes
コンパイル時間 2,419 ms
コンパイル使用メモリ 77,856 KB
実行使用メモリ 59,736 KB
最終ジャッジ日時 2024-04-25 05:26:59
合計ジャッジ時間 14,126 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
41,124 KB
testcase_01 AC 127 ms
41,456 KB
testcase_02 AC 127 ms
41,568 KB
testcase_03 AC 124 ms
41,536 KB
testcase_04 AC 127 ms
41,384 KB
testcase_05 AC 202 ms
45,788 KB
testcase_06 AC 182 ms
43,464 KB
testcase_07 AC 259 ms
47,488 KB
testcase_08 AC 779 ms
59,288 KB
testcase_09 AC 664 ms
52,628 KB
testcase_10 AC 846 ms
58,732 KB
testcase_11 AC 769 ms
58,240 KB
testcase_12 AC 823 ms
59,588 KB
testcase_13 AC 907 ms
59,156 KB
testcase_14 AC 995 ms
59,736 KB
testcase_15 AC 836 ms
58,780 KB
testcase_16 AC 889 ms
59,672 KB
testcase_17 AC 867 ms
59,492 KB
testcase_18 AC 780 ms
57,472 KB
testcase_19 AC 107 ms
40,652 KB
testcase_20 AC 113 ms
41,016 KB
testcase_21 AC 115 ms
41,236 KB
testcase_22 AC 104 ms
39,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] asc = new int[n];
        int[] dsc = new int[n];
        asc[0] = 1;
        dsc[0] = 1;
        long prev = sc.nextLong();
        for (int i = 1; i < n; i++) {
            long x = sc.nextLong();
            if (prev <= x) {
                asc[i] = asc[i - 1] + 1;
            } else {
                asc[i] = 1;
            }
            if (prev >= x) {
                dsc[i] = dsc[i - 1] + 1;
            } else {
                dsc[i] = 1;
            }
            prev = x;
        }
        int q = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            int left = sc.nextInt();
            int right = sc.nextInt();
            if (asc[right] - asc[left] == right - left) {
                sb.append(1);
            } else {
                sb.append(0);
            }
            sb.append(" ");
            if (dsc[right] - dsc[left] == right - left) {
                sb.append(1);
            } else {
                sb.append(0);
            }
            sb.append("\n");
       }
       System.out.print(sb);
    }
}
0