結果
問題 | No.1705 Mode of long array |
ユーザー | harurun |
提出日時 | 2021-09-19 18:26:01 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,122 ms / 3,000 ms |
コード長 | 2,876 bytes |
コンパイル時間 | 489 ms |
コンパイル使用メモリ | 87,312 KB |
実行使用メモリ | 199,112 KB |
最終ジャッジ日時 | 2023-09-30 09:42:09 |
合計ジャッジ時間 | 41,092 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 66 ms
71,632 KB |
testcase_01 | AC | 70 ms
71,084 KB |
testcase_02 | AC | 64 ms
71,552 KB |
testcase_03 | AC | 200 ms
79,892 KB |
testcase_04 | AC | 156 ms
79,064 KB |
testcase_05 | AC | 180 ms
79,916 KB |
testcase_06 | AC | 338 ms
85,664 KB |
testcase_07 | AC | 391 ms
85,352 KB |
testcase_08 | AC | 370 ms
83,412 KB |
testcase_09 | AC | 349 ms
85,808 KB |
testcase_10 | AC | 355 ms
87,232 KB |
testcase_11 | AC | 372 ms
84,320 KB |
testcase_12 | AC | 366 ms
85,960 KB |
testcase_13 | AC | 889 ms
177,600 KB |
testcase_14 | AC | 846 ms
149,392 KB |
testcase_15 | AC | 621 ms
129,824 KB |
testcase_16 | AC | 710 ms
144,056 KB |
testcase_17 | AC | 561 ms
124,172 KB |
testcase_18 | AC | 531 ms
116,456 KB |
testcase_19 | AC | 768 ms
156,772 KB |
testcase_20 | AC | 580 ms
128,460 KB |
testcase_21 | AC | 666 ms
162,304 KB |
testcase_22 | AC | 943 ms
199,112 KB |
testcase_23 | AC | 1,038 ms
113,596 KB |
testcase_24 | AC | 857 ms
110,244 KB |
testcase_25 | AC | 880 ms
114,756 KB |
testcase_26 | AC | 892 ms
111,232 KB |
testcase_27 | AC | 947 ms
114,356 KB |
testcase_28 | AC | 898 ms
113,040 KB |
testcase_29 | AC | 801 ms
111,112 KB |
testcase_30 | AC | 840 ms
113,216 KB |
testcase_31 | AC | 897 ms
109,592 KB |
testcase_32 | AC | 832 ms
114,112 KB |
testcase_33 | AC | 913 ms
194,976 KB |
testcase_34 | AC | 1,122 ms
195,704 KB |
testcase_35 | AC | 1,031 ms
192,812 KB |
testcase_36 | AC | 942 ms
194,544 KB |
testcase_37 | AC | 930 ms
192,900 KB |
testcase_38 | AC | 929 ms
194,676 KB |
testcase_39 | AC | 926 ms
196,096 KB |
testcase_40 | AC | 940 ms
194,604 KB |
testcase_41 | AC | 942 ms
195,332 KB |
testcase_42 | AC | 937 ms
196,328 KB |
testcase_43 | AC | 535 ms
121,232 KB |
testcase_44 | AC | 481 ms
121,524 KB |
testcase_45 | AC | 486 ms
121,596 KB |
testcase_46 | AC | 483 ms
121,336 KB |
testcase_47 | AC | 496 ms
121,852 KB |
testcase_48 | AC | 485 ms
122,024 KB |
testcase_49 | AC | 971 ms
157,144 KB |
testcase_50 | AC | 971 ms
156,200 KB |
testcase_51 | AC | 956 ms
154,912 KB |
testcase_52 | AC | 976 ms
154,556 KB |
testcase_53 | AC | 993 ms
155,828 KB |
ソースコード
# multiset: https://tsubo.hatenablog.jp/entry/2020/06/15/124657 from heapq import* def maxheappush(heap,x): heappush(heap,-x) return def maxheappop(heap): return -1*(heappop(heap)) def get_maxheap(heap): return -1*heap[0] class pseudo_set: def __init__(self): self.heap=[] self.di=set() return def insert(self,x): maxheappush(self.heap,x) if x not in self.di: self.di.add(x) return def erase(self,x): self.di.discard(x) while self.heap: p=maxheappop(self.heap) if p in self.di: maxheappush(self.heap,p) break return def get_max(self): while self.heap: p=maxheappop(self.heap) if p in self.di: maxheappush(self.heap,p) break return get_maxheap(self.heap) class pseudo_Multiset: def __init__(self): self.heap=[] self.di=dict() return def insert(self,x): maxheappush(self.heap,x) if x not in self.di: self.di[x]=1 else: self.di[x]+=1 return def erase(self,x): if x in self.di: self.di[x]-=1 if self.di[x]==0: self.di.pop(x) while self.heap: p=maxheappop(self.heap) if p in self.di: maxheappush(self.heap,p) break return def get_max(self): while self.heap: p=maxheappop(self.heap) if p in self.di: maxheappush(self.heap,p) break return get_maxheap(self.heap) class Mode: def __init__(self,M,um,A): self.place=um self.count=[0]*M self.S=[pseudo_set() for _ in [0]*len(um)] self.max_S=pseudo_Multiset() for i in range(M): self.max_S.insert(0) self.add(i,A[i]) return def add(self,x,y): now=self.count[x] self.S[self.place[now]].erase(x) self.max_S.erase(self.place[now]) self.S[self.place[now+y]].insert(x) self.max_S.insert(self.place[now+y]) self.count[x]+=y return def erase(self,x,y): now=self.count[x] self.S[self.place[now]].erase(x) self.max_S.erase(self.place[now]) self.S[self.place[now-y]].insert(x) self.max_S.insert(self.place[now-y]) self.count[x]-=y return def get(self): max_place=self.max_S.get_max() return self.S[max_place].get_max()+1 def main(): N,M=map(int,input().split()) a=list(map(int,input().split())) b=a[:] Q=int(input()) query=[] for i in range(Q): t,x,y=map(int,input().split()) query.append((t,x,y)) if t==1: b.append(b[x-1]) b[x-1]+=y elif t==2: b.append(b[x-1]) b[x-1]-=y b.append(0) b.sort() place=dict() place[b[0]]=0 cnt=1 for i in range(1,len(b)): if b[i-1]!=b[i]: place[b[i]]=cnt cnt+=1 mode=Mode(M,place,a) for t,x,y in query: if t==1: mode.add(x-1,y) elif t==2: mode.erase(x-1,y) else: print(mode.get()) return main()