結果
問題 | No.905 Sorted? |
ユーザー |
![]() |
提出日時 | 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+5BIT=[0]*(LEN+1)# 1-indexedなtreedef update(v,w):# index vにwを加えるwhile v<=LEN:BIT[v]+=wv+=(v&(-v))# 自分を含む大きなノードへ. たとえばv=3→v=4def getvalue(v):# [1,v]の区間の和を求めるANS=0while v!=0:ANS+=BIT[v]v-=(v&(-v))# 自分より小さい2ベキのノードへ. たとえばv=3→v=2へreturn ANSBIT2=[0]*(LEN+1)# 1-indexedなtreedef update2(v,w):# index vにwを加えるwhile v<=LEN:BIT2[v]+=wv+=(v&(-v))# 自分を含む大きなノードへ. たとえばv=3→v=4def getvalue2(v):# [1,v]の区間の和を求めるANS=0while v!=0:ANS+=BIT2[v]v-=(v&(-v))# 自分より小さい2ベキのノードへ. たとえばv=3→v=2へreturn ANSfor 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)