結果
問題 | 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,795 ms / 3,000 ms |
コード長 | 2,876 bytes |
コンパイル時間 | 208 ms |
コンパイル使用メモリ | 13,184 KB |
実行使用メモリ | 132,100 KB |
最終ジャッジ日時 | 2024-07-23 03:43:53 |
合計ジャッジ時間 | 53,305 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
11,392 KB |
testcase_01 | AC | 33 ms
11,264 KB |
testcase_02 | AC | 32 ms
11,264 KB |
testcase_03 | AC | 45 ms
11,648 KB |
testcase_04 | AC | 42 ms
11,392 KB |
testcase_05 | AC | 48 ms
11,648 KB |
testcase_06 | AC | 82 ms
12,672 KB |
testcase_07 | AC | 96 ms
12,928 KB |
testcase_08 | AC | 92 ms
12,800 KB |
testcase_09 | AC | 86 ms
12,544 KB |
testcase_10 | AC | 82 ms
12,544 KB |
testcase_11 | AC | 86 ms
12,800 KB |
testcase_12 | AC | 86 ms
12,544 KB |
testcase_13 | AC | 1,475 ms
108,976 KB |
testcase_14 | AC | 1,029 ms
78,300 KB |
testcase_15 | AC | 922 ms
57,012 KB |
testcase_16 | AC | 1,169 ms
69,904 KB |
testcase_17 | AC | 799 ms
52,648 KB |
testcase_18 | AC | 673 ms
47,528 KB |
testcase_19 | AC | 1,389 ms
85,288 KB |
testcase_20 | AC | 794 ms
58,500 KB |
testcase_21 | AC | 1,188 ms
94,152 KB |
testcase_22 | AC | 1,775 ms
132,100 KB |
testcase_23 | AC | 783 ms
33,020 KB |
testcase_24 | AC | 795 ms
33,020 KB |
testcase_25 | AC | 778 ms
33,404 KB |
testcase_26 | AC | 779 ms
33,148 KB |
testcase_27 | AC | 783 ms
33,144 KB |
testcase_28 | AC | 780 ms
33,020 KB |
testcase_29 | AC | 782 ms
33,276 KB |
testcase_30 | AC | 774 ms
33,148 KB |
testcase_31 | AC | 784 ms
33,020 KB |
testcase_32 | AC | 779 ms
33,144 KB |
testcase_33 | AC | 1,776 ms
114,688 KB |
testcase_34 | AC | 1,792 ms
114,928 KB |
testcase_35 | AC | 1,785 ms
114,752 KB |
testcase_36 | AC | 1,776 ms
114,688 KB |
testcase_37 | AC | 1,745 ms
114,716 KB |
testcase_38 | AC | 1,772 ms
114,708 KB |
testcase_39 | AC | 1,793 ms
114,804 KB |
testcase_40 | AC | 1,795 ms
114,860 KB |
testcase_41 | AC | 1,791 ms
114,720 KB |
testcase_42 | AC | 1,782 ms
114,772 KB |
testcase_43 | AC | 961 ms
42,276 KB |
testcase_44 | AC | 1,007 ms
45,428 KB |
testcase_45 | AC | 974 ms
45,408 KB |
testcase_46 | AC | 981 ms
45,528 KB |
testcase_47 | AC | 999 ms
45,392 KB |
testcase_48 | AC | 967 ms
45,508 KB |
testcase_49 | AC | 1,364 ms
76,512 KB |
testcase_50 | AC | 1,373 ms
76,500 KB |
testcase_51 | AC | 1,374 ms
76,648 KB |
testcase_52 | AC | 1,366 ms
76,528 KB |
testcase_53 | AC | 1,353 ms
76,532 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()