# 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 #print("get_max: ",get_maxheap(self.heap)) return get_maxheap(self.heap) class INPUT: def __init__(self): self._l=open(0).read().split() self._length=len(self._l) self._index=0 return def stream(self,k=1,f=int,f2=False): assert(-1 return left all #listを変数で受け取るとき、必ずlistをTrueにすること。 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() #print("get: ",self.S[max_place].di) return self.S[max_place].get_max()+1 def debug_count(self): for i in self.count: print(i,end=" ") print() return def debug_max_S(self): print(self.max_S.di) return def debug_S(self): for i in self.S: print(i.di,end=" ") print() return def main(): N,M=pin(2) a=pin(M,int,1) b=a[:] Q=pin(1) query=[] for i in range(Q): t,x,y=pin(3) 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 #print(0,end=" ") for i in range(1,len(b)): if b[i-1]!=b[i]: #print(b[i],end=" ") place[b[i]]=cnt cnt+=1 #print() mode=Mode(M,place,a) for t,x,y in query: #mode.debug_count() #mode.debug_max_S() #mode.debug_S() if t==1: mode.add(x-1,y) elif t==2: mode.erase(x-1,y) else: print(mode.get()) return main()