結果
問題 | No.1705 Mode of long array |
ユーザー | harurun |
提出日時 | 2021-09-19 18:27:06 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,416 ms / 3,000 ms |
コード長 | 2,876 bytes |
コンパイル時間 | 84 ms |
コンパイル使用メモリ | 11,264 KB |
実行使用メモリ | 131,772 KB |
最終ジャッジ日時 | 2023-09-30 09:39:56 |
合計ジャッジ時間 | 43,746 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 15 ms
8,652 KB |
testcase_01 | AC | 16 ms
8,656 KB |
testcase_02 | AC | 16 ms
8,652 KB |
testcase_03 | AC | 27 ms
8,856 KB |
testcase_04 | AC | 24 ms
8,804 KB |
testcase_05 | AC | 26 ms
8,856 KB |
testcase_06 | AC | 53 ms
10,216 KB |
testcase_07 | AC | 63 ms
10,320 KB |
testcase_08 | AC | 62 ms
10,428 KB |
testcase_09 | AC | 58 ms
10,080 KB |
testcase_10 | AC | 56 ms
10,072 KB |
testcase_11 | AC | 57 ms
10,356 KB |
testcase_12 | AC | 56 ms
10,240 KB |
testcase_13 | AC | 1,147 ms
108,688 KB |
testcase_14 | AC | 782 ms
77,000 KB |
testcase_15 | AC | 648 ms
55,336 KB |
testcase_16 | AC | 835 ms
68,492 KB |
testcase_17 | AC | 590 ms
50,732 KB |
testcase_18 | AC | 482 ms
45,736 KB |
testcase_19 | AC | 984 ms
83,980 KB |
testcase_20 | AC | 580 ms
56,812 KB |
testcase_21 | AC | 903 ms
93,240 KB |
testcase_22 | AC | 1,366 ms
131,772 KB |
testcase_23 | AC | 610 ms
30,216 KB |
testcase_24 | AC | 604 ms
30,268 KB |
testcase_25 | AC | 601 ms
30,904 KB |
testcase_26 | AC | 599 ms
30,580 KB |
testcase_27 | AC | 625 ms
30,468 KB |
testcase_28 | AC | 630 ms
30,452 KB |
testcase_29 | AC | 624 ms
30,712 KB |
testcase_30 | AC | 613 ms
30,392 KB |
testcase_31 | AC | 672 ms
30,208 KB |
testcase_32 | AC | 634 ms
30,408 KB |
testcase_33 | AC | 1,362 ms
113,752 KB |
testcase_34 | AC | 1,358 ms
113,692 KB |
testcase_35 | AC | 1,392 ms
113,772 KB |
testcase_36 | AC | 1,409 ms
113,688 KB |
testcase_37 | AC | 1,366 ms
113,616 KB |
testcase_38 | AC | 1,341 ms
113,608 KB |
testcase_39 | AC | 1,360 ms
113,756 KB |
testcase_40 | AC | 1,341 ms
113,872 KB |
testcase_41 | AC | 1,356 ms
113,692 KB |
testcase_42 | AC | 1,416 ms
113,804 KB |
testcase_43 | AC | 733 ms
40,336 KB |
testcase_44 | AC | 777 ms
43,496 KB |
testcase_45 | AC | 786 ms
43,476 KB |
testcase_46 | AC | 771 ms
43,476 KB |
testcase_47 | AC | 768 ms
43,524 KB |
testcase_48 | AC | 781 ms
43,428 KB |
testcase_49 | AC | 1,058 ms
74,552 KB |
testcase_50 | AC | 1,086 ms
74,612 KB |
testcase_51 | AC | 1,053 ms
74,636 KB |
testcase_52 | AC | 1,040 ms
74,564 KB |
testcase_53 | AC | 1,048 ms
74,604 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()