結果

問題 No.905 Sorted?
ユーザー titiatitia
提出日時 2019-10-11 21:39:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,181 ms / 2,000 ms
コード長 1,243 bytes
コンパイル時間 438 ms
コンパイル使用メモリ 11,048 KB
実行使用メモリ 34,000 KB
最終ジャッジ日時 2023-08-16 17:25:26
合計ジャッジ時間 11,969 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,308 KB
testcase_01 AC 17 ms
8,304 KB
testcase_02 AC 16 ms
8,312 KB
testcase_03 AC 16 ms
8,292 KB
testcase_04 AC 18 ms
8,332 KB
testcase_05 AC 23 ms
8,672 KB
testcase_06 AC 20 ms
8,428 KB
testcase_07 AC 35 ms
9,236 KB
testcase_08 AC 800 ms
27,704 KB
testcase_09 AC 534 ms
21,584 KB
testcase_10 AC 771 ms
27,076 KB
testcase_11 AC 871 ms
28,820 KB
testcase_12 AC 994 ms
31,348 KB
testcase_13 AC 863 ms
29,140 KB
testcase_14 AC 896 ms
29,772 KB
testcase_15 AC 874 ms
28,736 KB
testcase_16 AC 1,181 ms
34,000 KB
testcase_17 AC 990 ms
33,520 KB
testcase_18 AC 763 ms
27,576 KB
testcase_19 AC 16 ms
8,260 KB
testcase_20 AC 16 ms
8,264 KB
testcase_21 AC 16 ms
8,140 KB
testcase_22 AC 16 ms
7,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)

    
0