結果
| 問題 |
No.905 Sorted?
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2019-10-11 21:39:53 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 1,384 ms / 2,000 ms |
| コード長 | 1,243 bytes |
| コンパイル時間 | 286 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 35,916 KB |
| 最終ジャッジ日時 | 2024-11-25 07:02:29 |
| 合計ジャッジ時間 | 12,755 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
Query=[list(map(int,input().split())) for i in range(Q)]
LEN=N+5
BIT=[0]*(LEN+1)# 1-indexedなtree
def update(v,w):# index vにwを加える
while v<=LEN:
BIT[v]+=w
v+=(v&(-v))# 自分を含む大きなノードへ. たとえばv=3→v=4
def getvalue(v):# [1,v]の区間の和を求める
ANS=0
while v!=0:
ANS+=BIT[v]
v-=(v&(-v))# 自分より小さい2ベキのノードへ. たとえばv=3→v=2へ
return ANS
BIT2=[0]*(LEN+1)# 1-indexedなtree
def update2(v,w):# index vにwを加える
while v<=LEN:
BIT2[v]+=w
v+=(v&(-v))# 自分を含む大きなノードへ. たとえばv=3→v=4
def getvalue2(v):# [1,v]の区間の和を求める
ANS=0
while v!=0:
ANS+=BIT2[v]
v-=(v&(-v))# 自分より小さい2ベキのノードへ. たとえばv=3→v=2へ
return ANS
for i in range(1,N):
if A[i]>=A[i-1]:
update(i,1)
if A[i]<=A[i-1]:
update2(i,1)
for x,y in Query:
if getvalue(y)-getvalue(x)==y-x:
print(1,end=" ")
else:
print(0,end=" ")
if getvalue2(y)-getvalue2(x)==y-x:
print(1)
else:
print(0)
titia