結果

問題 No.905 Sorted?
ユーザー FromBooskaFromBooska
提出日時 2023-04-04 15:06:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 353 ms / 2,000 ms
コード長 1,118 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 101,616 KB
最終ジャッジ日時 2024-04-08 14:44:38
合計ジャッジ時間 5,806 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
53,332 KB
testcase_01 AC 37 ms
53,332 KB
testcase_02 AC 38 ms
53,332 KB
testcase_03 AC 37 ms
53,332 KB
testcase_04 AC 36 ms
53,332 KB
testcase_05 AC 55 ms
66,368 KB
testcase_06 AC 48 ms
62,228 KB
testcase_07 AC 68 ms
72,668 KB
testcase_08 AC 340 ms
87,636 KB
testcase_09 AC 244 ms
85,232 KB
testcase_10 AC 314 ms
97,736 KB
testcase_11 AC 325 ms
95,104 KB
testcase_12 AC 353 ms
92,464 KB
testcase_13 AC 325 ms
92,676 KB
testcase_14 AC 332 ms
98,028 KB
testcase_15 AC 342 ms
100,964 KB
testcase_16 AC 347 ms
101,616 KB
testcase_17 AC 344 ms
101,580 KB
testcase_18 AC 283 ms
101,580 KB
testcase_19 AC 36 ms
53,332 KB
testcase_20 AC 35 ms
53,332 KB
testcase_21 AC 36 ms
53,332 KB
testcase_22 AC 35 ms
53,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# セグメントツリーで通ったが公式解説はスマート
# 累積和を2つ用意する、広義増加と広義減少
# 広義増加を満たしていれば+1していく累積和
# 範囲差と累積和差が等しければ1
# 2つの問題があるので、同時に解かずに別々に解くイメージ

N = int(input())
A = list(map(int, input().split()))
B_increase = []
for i in range(N):
    if i == 0:
        B_increase.append(1)
    else:
        if A[i] >= A[i-1]:
            B_increase.append(B_increase[-1]+1)
        else:
            B_increase.append(B_increase[-1])
B_decrease = []
for i in range(N):
    if i == 0:
        B_decrease.append(1)
    else:
        if A[i] <= A[i-1]:
            B_decrease.append(B_decrease[-1]+1)
        else:
            B_decrease.append(B_decrease[-1])
            
#print(B_increase)
#print(B_decrease)

Q = int(input())
for q in range(Q):
    l, r = map(int, input().split())
    ans1 = 0
    if B_increase[r]-B_increase[l] == r-l:
        ans1 = 1
    ans2 = 0
    if B_decrease[r]-B_decrease[l] == r-l:
        ans2 = 1    
    print(ans1, ans2)
0