#include #include #include #include using namespace std; using ll=long long; using Pll=pair; int main(){ ll N,M; cin>>N>>M; vector a(M); for(ll i=0;i>a.at(i); } multiset ms; for(ll i=0;i>Q; for(ll i=0;i>T>>X>>Y; if(T==1){ auto it=ms.lower_bound(make_pair(a.at(X-1),-1)); auto last=ms.upper_bound(make_pair(a.at(X-1)+1,-1)); for(;it!=last;it++){ if((*it).second==X){ ms.erase(it); break; } } a.at(X-1)+=Y; ms.insert(make_pair(a.at(X-1),X)); }else if(T==2){ auto it=ms.lower_bound(make_pair(a.at(X-1),-1)); auto last=ms.upper_bound(make_pair(a.at(X-1)+1,-1)); for(;it!=last;it++){ if((*it).second==X){ ms.erase(it); break; } } a.at(X-1)-=Y; ms.insert(make_pair(a.at(X-1),X)); }else{ auto it=ms.lower_bound(make_pair((*ms.rbegin()).first,-1)); auto last=ms.upper_bound(make_pair((*ms.rbegin()).first+1,-1)); ll ans=0; for(;it!=last;it++){ ans=max(ans,(*it).second); } cout<