結果
問題 | No.905 Sorted? |
ユーザー |
![]() |
提出日時 | 2023-04-04 15:06:19 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 335 ms / 2,000 ms |
コード長 | 1,118 bytes |
コンパイル時間 | 237 ms |
コンパイル使用メモリ | 82,108 KB |
実行使用メモリ | 102,236 KB |
最終ジャッジ日時 | 2024-10-01 07:23:59 |
合計ジャッジ時間 | 5,259 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
# セグメントツリーで通ったが公式解説はスマート # 累積和を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)