結果
問題 | No.1705 Mode of long array |
ユーザー | harurun |
提出日時 | 2021-09-19 18:26:01 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,140 ms / 3,000 ms |
コード長 | 2,876 bytes |
コンパイル時間 | 380 ms |
コンパイル使用メモリ | 82,212 KB |
実行使用メモリ | 203,136 KB |
最終ジャッジ日時 | 2024-07-23 03:47:03 |
合計ジャッジ時間 | 42,660 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
54,208 KB |
testcase_01 | AC | 39 ms
53,756 KB |
testcase_02 | AC | 40 ms
54,008 KB |
testcase_03 | AC | 169 ms
78,896 KB |
testcase_04 | AC | 138 ms
78,700 KB |
testcase_05 | AC | 179 ms
79,692 KB |
testcase_06 | AC | 339 ms
81,864 KB |
testcase_07 | AC | 406 ms
83,180 KB |
testcase_08 | AC | 374 ms
82,488 KB |
testcase_09 | AC | 356 ms
82,384 KB |
testcase_10 | AC | 337 ms
82,392 KB |
testcase_11 | AC | 348 ms
81,816 KB |
testcase_12 | AC | 354 ms
81,892 KB |
testcase_13 | AC | 981 ms
179,672 KB |
testcase_14 | AC | 766 ms
146,588 KB |
testcase_15 | AC | 708 ms
127,352 KB |
testcase_16 | AC | 819 ms
137,480 KB |
testcase_17 | AC | 644 ms
121,572 KB |
testcase_18 | AC | 594 ms
115,828 KB |
testcase_19 | AC | 876 ms
153,184 KB |
testcase_20 | AC | 653 ms
124,844 KB |
testcase_21 | AC | 739 ms
161,160 KB |
testcase_22 | AC | 1,095 ms
203,136 KB |
testcase_23 | AC | 896 ms
106,560 KB |
testcase_24 | AC | 913 ms
106,944 KB |
testcase_25 | AC | 916 ms
106,816 KB |
testcase_26 | AC | 894 ms
107,840 KB |
testcase_27 | AC | 971 ms
108,216 KB |
testcase_28 | AC | 954 ms
107,456 KB |
testcase_29 | AC | 858 ms
106,424 KB |
testcase_30 | AC | 896 ms
106,172 KB |
testcase_31 | AC | 923 ms
107,072 KB |
testcase_32 | AC | 915 ms
106,300 KB |
testcase_33 | AC | 1,103 ms
192,644 KB |
testcase_34 | AC | 1,088 ms
193,392 KB |
testcase_35 | AC | 1,085 ms
193,060 KB |
testcase_36 | AC | 1,091 ms
194,004 KB |
testcase_37 | AC | 1,093 ms
192,772 KB |
testcase_38 | AC | 1,103 ms
193,228 KB |
testcase_39 | AC | 1,125 ms
193,336 KB |
testcase_40 | AC | 1,140 ms
193,324 KB |
testcase_41 | AC | 1,138 ms
193,328 KB |
testcase_42 | AC | 1,126 ms
193,484 KB |
testcase_43 | AC | 493 ms
118,512 KB |
testcase_44 | AC | 520 ms
117,560 KB |
testcase_45 | AC | 518 ms
118,352 KB |
testcase_46 | AC | 522 ms
118,512 KB |
testcase_47 | AC | 541 ms
118,632 KB |
testcase_48 | AC | 539 ms
118,636 KB |
testcase_49 | AC | 1,081 ms
149,576 KB |
testcase_50 | AC | 1,059 ms
149,068 KB |
testcase_51 | AC | 1,059 ms
149,572 KB |
testcase_52 | AC | 1,078 ms
150,220 KB |
testcase_53 | AC | 1,060 ms
150,592 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()