結果

問題 No.1705 Mode of long array
ユーザー vwxyzvwxyz
提出日時 2021-10-08 23:21:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,305 ms / 3,000 ms
コード長 4,067 bytes
コンパイル時間 68 ms
コンパイル使用メモリ 11,420 KB
実行使用メモリ 25,492 KB
最終ジャッジ日時 2023-09-30 13:18:28
合計ジャッジ時間 39,393 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,680 KB
testcase_01 AC 17 ms
8,724 KB
testcase_02 AC 17 ms
8,680 KB
testcase_03 AC 28 ms
8,848 KB
testcase_04 AC 27 ms
8,688 KB
testcase_05 AC 31 ms
8,688 KB
testcase_06 AC 67 ms
8,776 KB
testcase_07 AC 77 ms
8,932 KB
testcase_08 AC 72 ms
8,924 KB
testcase_09 AC 64 ms
8,916 KB
testcase_10 AC 63 ms
8,848 KB
testcase_11 AC 70 ms
8,812 KB
testcase_12 AC 67 ms
8,828 KB
testcase_13 AC 900 ms
20,292 KB
testcase_14 AC 689 ms
15,236 KB
testcase_15 AC 762 ms
10,344 KB
testcase_16 AC 954 ms
11,328 KB
testcase_17 AC 683 ms
10,412 KB
testcase_18 AC 551 ms
11,064 KB
testcase_19 AC 994 ms
13,980 KB
testcase_20 AC 608 ms
12,428 KB
testcase_21 AC 676 ms
18,544 KB
testcase_22 AC 1,031 ms
22,008 KB
testcase_23 AC 439 ms
8,820 KB
testcase_24 AC 439 ms
8,684 KB
testcase_25 AC 435 ms
8,660 KB
testcase_26 AC 440 ms
8,428 KB
testcase_27 AC 437 ms
8,680 KB
testcase_28 AC 440 ms
8,820 KB
testcase_29 AC 434 ms
8,604 KB
testcase_30 AC 438 ms
8,676 KB
testcase_31 AC 438 ms
8,756 KB
testcase_32 AC 442 ms
8,756 KB
testcase_33 AC 1,020 ms
25,408 KB
testcase_34 AC 1,019 ms
25,456 KB
testcase_35 AC 1,016 ms
25,460 KB
testcase_36 AC 1,009 ms
25,340 KB
testcase_37 AC 1,016 ms
25,484 KB
testcase_38 AC 1,010 ms
25,328 KB
testcase_39 AC 1,017 ms
25,468 KB
testcase_40 AC 1,019 ms
25,492 KB
testcase_41 AC 1,014 ms
25,260 KB
testcase_42 AC 1,016 ms
25,332 KB
testcase_43 AC 1,109 ms
22,164 KB
testcase_44 AC 1,291 ms
22,196 KB
testcase_45 AC 1,258 ms
22,244 KB
testcase_46 AC 1,286 ms
22,244 KB
testcase_47 AC 1,305 ms
22,168 KB
testcase_48 AC 1,281 ms
22,336 KB
testcase_49 AC 1,024 ms
22,548 KB
testcase_50 AC 1,025 ms
22,428 KB
testcase_51 AC 1,020 ms
22,508 KB
testcase_52 AC 1,017 ms
22,552 KB
testcase_53 AC 1,022 ms
22,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline=sys.stdin.readline
class Segment_Tree:
    def __init__(self,N,f,e,lst=None):
        self.f=f
        self.e=e
        self.N=N
        if lst==None:
            self.segment_tree=[self.e]*2*self.N
        else:
            assert len(lst)<=self.N
            self.segment_tree=[self.e]*self.N+[x for x in lst]+[self.e]*(N-len(lst))
            for i in range(self.N-1,0,-1):
                self.segment_tree[i]=self.f(self.segment_tree[i<<1],self.segment_tree[i<<1|1])

    def __getitem__(self,i):
        if type(i)==int:
            if -self.N<=i<0:
                return self.segment_tree[i+self.N*2]
            elif 0<=i<self.N:
                return self.segment_tree[i+self.N]
            else:
                raise IndexError('list index out of range')
        else:
            a,b,c=i.start,i.stop,i.step
            if a==None or a<-self.N:
                a=self.N
            elif self.N<=a:
                a=self.N*2
            elif a<0:
                a+=self.N*2
            else:
                a+=self.N
            if b==None or self.N<=b:
                b=self.N*2
            elif b<-self.N:
                b=self.N
            elif b<0:
                b+=self.N*2
            else:
                b+=self.N
            return self.segment_tree[slice(a,b,c)]

    def __setitem__(self,i,x):
        if -self.N<=i<0:
            i+=self.N*2
        elif 0<=i<self.N:
            i+=self.N
        else:
            raise IndexError('list index out of range')
        self.segment_tree[i]=x
        while i>1:
            i>>= 1
            self.segment_tree[i]=self.f(self.segment_tree[i<<1],self.segment_tree[i<<1|1])

    def Build(self,lst):
        for i,x in enumerate(lst,self.N):
            self.segment_tree[i]=x
        for i in range(self.N-1,0,-1):
            self.segment_tree[i]=self.f(self.segment_tree[i<<1],self.segment_tree[i<<1|1])

    def Fold(self,L=None,R=None):
        if L==None or L<-self.N:
            L=self.N
        elif self.N<=L:
            L=self.N*2
        elif L<0:
            L+=self.N*2
        else:
            L+=self.N
        if R==None or self.N<=R:
            R=self.N*2
        elif R<-self.N:
            R=self.N
        elif R<0:
            R+=self.N*2
        else:
            R+=self.N
        vL=self.e
        vR=self.e
        while L<R:
            if L&1:
                vL=self.f(vL,self.segment_tree[L])
                L+=1
            if R&1:
                R-=1
                vR=self.f(self.segment_tree[R],vR)
            L>>=1
            R>>=1
        return self.f(vL,vR)

    def Fold_Index(self,L=None,R=None):
        if L==None or L<-self.N:
            L=self.N
        elif self.N<=L:
            L=self.N*2
        elif L<0:
            L+=self.N*2
        else:
            L+=self.N
        if R==None or self.N<=R:
            R=self.N*2
        elif R<-self.N:
            R=self.N
        elif R<0:
            R+=self.N*2
        else:
            R+=self.N
        if L==R:
            return None
        x=self.Fold(L-self.N,R-self.N)
        while L<R:
            if L&1:
                if self.segment_tree[L]==x:
                    i=L
                    break
                L+=1
            if R&1:
                R-=1
                if self.segment_tree[R]==x:
                    i=R
                    break
            L>>=1
            R>>=1
        while i<self.N:
            if self.segment_tree[i]==self.segment_tree[i<<1]:
                i<<=1
            else:
                i<<=1
                i|=1
        i-=self.N
        return i

    def __str__(self):
        return '['+', '.join(map(str,self.segment_tree[self.N:]))+']'

N,M=map(int,readline().split())
A=list(map(int,readline().split()))
lst=[0]+[i+1+(A[i]<<20) for i in range(M)]
Q=int(readline())
inf=1<<60
ST=Segment_Tree(M+1,max,-inf,lst=lst)
for _ in range(Q):
    T,X,Y=map(int,readline().split())
    if T==1:
        ST[X]+=Y<<20
    elif T==2:
        ST[X]-=Y<<20
    else:
        ans=ST.Fold_Index()
        print(ans)
0