#include using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) #define all(x) x.begin(),x.end() using ll=long long; struct FenwickTree{ vector tree; int size; int start; FenwickTree(int sz){ size+=sz; tree.resize(size+1); start=0; while((1<<(start+1))<=size)start++; } void add(int pos,int val){ pos++; while(pos<=size){ tree[pos]+=val; pos+=pos&-pos; } } int bisect(int pos){ int now=0; int val=0; for(int i=start; i>=0; i--){ if(now+(1<>N>>Q; vector A(N); vector press; rep(i,N){ cin>>A[i]; press.emplace_back(A[i]); } vector> query(Q); rep(i,Q){ cin>>get<0>(query[i]); switch(get<0>(query[i])){ case 3: cin>>get<1>(query[i]); break; case 1: cin>>get<1>(query[i])>>get<2>(query[i]); press.emplace_back(get<2>(query[i])); } } sort(all(press)); press.erase(unique(all(press)),press.end()); FenwickTree a(press.size()); rep(i,Q){ if(get<0>(query[i])==1){ get<2>(query[i])=lower_bound(all(press),get<2>(query[i]))-press.begin(); } } vector change(N,-1); stack> chq; stack upd; rep(i,N){ A[i]=lower_bound(all(press),A[i])-press.begin(); change[i]=A[i]; upd.push(i); } a.add(0,N); rep(i,Q){ int t=get<0>(query[i]); if(t==1){ int k;int x; tie(ignore,k,x)=query[i]; change[k-1]=x; upd.push(k-1); } if(t==2){ while(!upd.empty()){ if(change[upd.top()]!=-1){ chq.push({a.bisect(upd.top()),change[upd.top()]}); change[upd.top()]=-1; } upd.pop(); } while(!chq.empty()){ a.add(chq.top().first,-1); a.add(chq.top().second,1); chq.pop(); } } if(t==3){ int x=get<1>(query[i]); if(change[x-1]!=-1){ cout<