結果
問題 | No.1705 Mode of long array |
ユーザー | vwxyz |
提出日時 | 2021-10-08 23:21:51 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,564 ms / 3,000 ms |
コード長 | 4,067 bytes |
コンパイル時間 | 188 ms |
コンパイル使用メモリ | 13,184 KB |
実行使用メモリ | 28,936 KB |
最終ジャッジ日時 | 2024-07-23 07:20:14 |
合計ジャッジ時間 | 46,001 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 33 ms
11,264 KB |
testcase_01 | AC | 31 ms
11,136 KB |
testcase_02 | AC | 30 ms
11,136 KB |
testcase_03 | AC | 42 ms
11,136 KB |
testcase_04 | AC | 39 ms
11,136 KB |
testcase_05 | AC | 46 ms
11,392 KB |
testcase_06 | AC | 87 ms
11,392 KB |
testcase_07 | AC | 106 ms
11,264 KB |
testcase_08 | AC | 95 ms
11,136 KB |
testcase_09 | AC | 86 ms
11,264 KB |
testcase_10 | AC | 87 ms
11,264 KB |
testcase_11 | AC | 94 ms
11,392 KB |
testcase_12 | AC | 90 ms
11,392 KB |
testcase_13 | AC | 1,094 ms
22,804 KB |
testcase_14 | AC | 838 ms
17,864 KB |
testcase_15 | AC | 948 ms
12,928 KB |
testcase_16 | AC | 1,147 ms
14,080 KB |
testcase_17 | AC | 822 ms
13,052 KB |
testcase_18 | AC | 659 ms
13,184 KB |
testcase_19 | AC | 1,199 ms
16,288 KB |
testcase_20 | AC | 751 ms
14,496 KB |
testcase_21 | AC | 808 ms
21,200 KB |
testcase_22 | AC | 1,260 ms
24,720 KB |
testcase_23 | AC | 506 ms
11,264 KB |
testcase_24 | AC | 510 ms
11,136 KB |
testcase_25 | AC | 505 ms
11,136 KB |
testcase_26 | AC | 510 ms
11,136 KB |
testcase_27 | AC | 508 ms
11,136 KB |
testcase_28 | AC | 512 ms
11,136 KB |
testcase_29 | AC | 505 ms
11,264 KB |
testcase_30 | AC | 519 ms
11,264 KB |
testcase_31 | AC | 518 ms
11,264 KB |
testcase_32 | AC | 516 ms
11,264 KB |
testcase_33 | AC | 1,296 ms
28,936 KB |
testcase_34 | AC | 1,245 ms
28,932 KB |
testcase_35 | AC | 1,250 ms
28,800 KB |
testcase_36 | AC | 1,222 ms
28,804 KB |
testcase_37 | AC | 1,208 ms
28,892 KB |
testcase_38 | AC | 1,219 ms
28,804 KB |
testcase_39 | AC | 1,216 ms
28,804 KB |
testcase_40 | AC | 1,255 ms
28,928 KB |
testcase_41 | AC | 1,263 ms
28,800 KB |
testcase_42 | AC | 1,258 ms
28,928 KB |
testcase_43 | AC | 1,343 ms
25,720 KB |
testcase_44 | AC | 1,550 ms
25,736 KB |
testcase_45 | AC | 1,561 ms
25,736 KB |
testcase_46 | AC | 1,564 ms
25,740 KB |
testcase_47 | AC | 1,558 ms
25,780 KB |
testcase_48 | AC | 1,546 ms
25,780 KB |
testcase_49 | AC | 1,226 ms
25,736 KB |
testcase_50 | AC | 1,248 ms
25,736 KB |
testcase_51 | AC | 1,259 ms
25,732 KB |
testcase_52 | AC | 1,255 ms
25,732 KB |
testcase_53 | AC | 1,224 ms
25,740 KB |
ソースコード
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)