結果

問題 No.905 Sorted?
ユーザー titiatitia
提出日時 2019-10-11 21:39:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,314 ms / 2,000 ms
コード長 1,243 bytes
コンパイル時間 115 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 36,092 KB
最終ジャッジ日時 2024-05-04 01:13:56
合計ジャッジ時間 12,496 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,752 KB
testcase_01 AC 27 ms
10,880 KB
testcase_02 AC 25 ms
10,880 KB
testcase_03 AC 27 ms
11,008 KB
testcase_04 AC 27 ms
11,008 KB
testcase_05 AC 33 ms
11,136 KB
testcase_06 AC 30 ms
11,008 KB
testcase_07 AC 48 ms
11,776 KB
testcase_08 AC 912 ms
30,208 KB
testcase_09 AC 610 ms
23,976 KB
testcase_10 AC 884 ms
29,448 KB
testcase_11 AC 971 ms
31,044 KB
testcase_12 AC 1,123 ms
33,900 KB
testcase_13 AC 959 ms
31,952 KB
testcase_14 AC 997 ms
31,816 KB
testcase_15 AC 967 ms
31,228 KB
testcase_16 AC 1,314 ms
35,996 KB
testcase_17 AC 1,121 ms
36,092 KB
testcase_18 AC 858 ms
30,208 KB
testcase_19 AC 26 ms
10,880 KB
testcase_20 AC 25 ms
10,880 KB
testcase_21 AC 26 ms
10,880 KB
testcase_22 AC 26 ms
10,880 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