結果

問題 No.905 Sorted?
ユーザー GrayCoderGrayCoder
提出日時 2019-10-11 22:24:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 272 ms / 2,000 ms
コード長 677 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 10,952 KB
実行使用メモリ 34,012 KB
最終ジャッジ日時 2023-08-16 18:34:27
合計ジャッジ時間 4,619 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
7,820 KB
testcase_01 AC 13 ms
7,864 KB
testcase_02 AC 14 ms
7,860 KB
testcase_03 AC 13 ms
7,816 KB
testcase_04 AC 13 ms
7,976 KB
testcase_05 AC 15 ms
8,800 KB
testcase_06 AC 14 ms
8,520 KB
testcase_07 AC 18 ms
9,384 KB
testcase_08 AC 226 ms
25,800 KB
testcase_09 AC 157 ms
20,748 KB
testcase_10 AC 223 ms
29,084 KB
testcase_11 AC 232 ms
28,824 KB
testcase_12 AC 269 ms
29,844 KB
testcase_13 AC 250 ms
31,020 KB
testcase_14 AC 254 ms
30,748 KB
testcase_15 AC 263 ms
27,424 KB
testcase_16 AC 272 ms
33,868 KB
testcase_17 AC 272 ms
34,012 KB
testcase_18 AC 205 ms
30,052 KB
testcase_19 AC 14 ms
7,860 KB
testcase_20 AC 13 ms
7,780 KB
testcase_21 AC 13 ms
7,956 KB
testcase_22 AC 13 ms
7,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    LR = [tuple(map(int, input().split())) for _ in [0] * Q]

    fn = [0] * N
    gn = fn[:]
    for i in range(1, N):
        if A[i-1] <= A[i]:
            fn[i] = fn[i-1] + 1
        else:
            fn[i] = fn[i-1] - 1
        if A[i-1] >= A[i]:
            gn[i] = gn[i-1] - 1
        else:
            gn[i] = gn[i-1] + 1

    for l, r in LR:
        f, g = 0, 0
        n = r - l
        if fn[r] - fn[l] == n:
            f = 1
        if gn[r] - gn[l] == -n:
            g = 1
        print(f, g)


main()
0