結果

問題 No.2809 Sort Query
ユーザー highlighterhighlighter
提出日時 2024-04-21 17:49:52
言語 PyPy3
(7.3.15)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,503 bytes
コンパイル時間 586 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 230,400 KB
最終ジャッジ日時 2024-07-12 20:53:16
合計ジャッジ時間 66,951 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
54,144 KB
testcase_01 AC 1,094 ms
194,844 KB
testcase_02 AC 937 ms
188,964 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 751 ms
142,088 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 758 ms
142,152 KB
testcase_10 AC 747 ms
142,280 KB
testcase_11 AC 773 ms
158,992 KB
testcase_12 AC 771 ms
163,564 KB
testcase_13 AC 756 ms
158,484 KB
testcase_14 AC 764 ms
160,296 KB
testcase_15 AC 784 ms
160,572 KB
testcase_16 AC 779 ms
161,408 KB
testcase_17 AC 763 ms
159,168 KB
testcase_18 AC 769 ms
161,660 KB
testcase_19 AC 782 ms
160,600 KB
testcase_20 AC 768 ms
157,952 KB
testcase_21 AC 1,042 ms
229,500 KB
testcase_22 AC 1,041 ms
222,988 KB
testcase_23 AC 1,021 ms
229,876 KB
testcase_24 AC 1,048 ms
230,400 KB
testcase_25 AC 1,023 ms
229,488 KB
testcase_26 AC 1,025 ms
228,324 KB
testcase_27 AC 1,007 ms
228,336 KB
testcase_28 AC 1,001 ms
228,600 KB
testcase_29 AC 1,012 ms
228,348 KB
testcase_30 AC 1,015 ms
228,344 KB
testcase_31 AC 735 ms
166,788 KB
testcase_32 AC 785 ms
167,544 KB
testcase_33 AC 745 ms
168,328 KB
testcase_34 AC 764 ms
165,628 KB
testcase_35 AC 748 ms
168,568 KB
testcase_36 AC 783 ms
178,276 KB
testcase_37 AC 761 ms
178,596 KB
testcase_38 AC 775 ms
178,588 KB
testcase_39 AC 769 ms
178,356 KB
testcase_40 AC 773 ms
178,444 KB
testcase_41 AC 932 ms
184,616 KB
testcase_42 AC 929 ms
184,888 KB
testcase_43 AC 942 ms
184,484 KB
testcase_44 AC 928 ms
184,364 KB
testcase_45 AC 966 ms
184,244 KB
testcase_46 AC 804 ms
181,928 KB
testcase_47 AC 802 ms
182,316 KB
testcase_48 AC 803 ms
182,156 KB
testcase_49 AC 898 ms
181,936 KB
testcase_50 AC 851 ms
182,108 KB
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 AC 595 ms
169,504 KB
testcase_61 AC 794 ms
164,224 KB
testcase_62 AC 663 ms
150,176 KB
testcase_63 WA -
testcase_64 AC 966 ms
183,508 KB
testcase_65 AC 537 ms
153,316 KB
testcase_66 WA -
testcase_67 WA -
testcase_68 AC 41 ms
54,144 KB
testcase_69 WA -
testcase_70 AC 41 ms
54,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
from array import array

class FenwickTree:
    def __init__(self,size):
        self.tree=array("i",[0]*(size+1))
        self.size=size
        self.start=size.bit_length()-1
    def add(self,pos,val):
        pos+=1
        while pos<=self.size:
            self.tree[pos]+=val
            pos+=pos&-pos
    def bisect(self,pos):
        now=0
        val=0
        for i in range(self.start,-1,-1):
            if now+(1<<i)<=self.size and val+self.tree[now+(1<<i)]<=pos:
                now+=1<<i
                val+=self.tree[now]
        return now

N,Q=map(int,input().split())
A=list(map(int,input().split()))
query=[tuple(map(int,input().split())) for i in range(Q)]
press=A[:]
for i in range(Q):
    if query[i][0]==1:
        press.append(query[i][2])
press.sort()
ser={}
for i in range(len(press)):
    ser[press[i]]=i
a=FenwickTree(len(press))
for i in range(N):
    A[i]=ser[A[i]]
    a.add(A[i],1)
change=[-1]*N
chq=deque()
changed=set()
for i in range(Q):
    t,*q=query[i]
    if t==1:
        k,x=q
        x=ser[x]
        change[k-1]=x
        changed.add(k-1)
    if t==2:
        for j in changed:
            chq.append((a.bisect(j),change[j]))
            change[j]=-1;
        changed.clear()
        while chq:
            a.add(chq[-1][0],-1)
            a.add(chq[-1][1],1)
            chq.pop()
    if t==3:
        k=q[0]
        if change[k-1]==-1:
            print(press[a.bisect(k-1)])
        else:
            print(press[change[k-1]])
0