#include #define ff first #define ss second #define pb push_back using namespace std; typedef long long ll; typedef pair pii; const int mod=998244353; inline int add(int x,int y){int ret=x+y;if(ret>=mod)ret-=mod;return ret;} inline int sub(int x,int y){int ret=x-y;if(ret<0)ret+=mod;return ret;} inline int mul(int x,int y){return ((ll)x*y)%mod;} inline int step(int base,int pw){int ret=1;while(pw){if(pw&1)ret=mul(ret,base);base=mul(base,base);pw>>=1;}return ret;} inline int invv(int x){return step(x,mod-2);} inline char gc() { // like getchar() static char buf[1 << 16]; static size_t bc, be; if (bc >= be) { buf[0] = 0, bc = 0; be = fread(buf, 1, sizeof(buf), stdin); } return buf[bc++]; // returns 0 on EOF } int readInt() { int a, c; while ((a = gc()) < 40); if (a == '-') return -readInt(); while ((c = gc()) >= 48) a = a * 10 + c - 480; return a - 48; } struct fenwick{ vectorbit; int n; fenwick(){ n=0; } fenwick(int n){ bit.resize(n+1); this->n=n; } void add(int x,ll val){ while(x<=n){ bit[x]+=val; x+=(x&(-x)); } } ll get(int x){ ll ret=0; while(x){ ret+=bit[x]; x-=(x&(-x)); } return ret; } ll get(int l,int r){ return get(r)-get(l-1); } }; const int maxn=2e5+10; int n,q; vectorvect[2][maxn]; struct qqq{ int tip; int id,x,y; int p,nval,rez; }; vectorqrys; int nstart[2][maxn],nend[2][maxn],ctm[2],niz[2][maxn]; void dfs(int x,int cc){ nstart[cc][x]=++ctm[cc]; niz[cc][ctm[cc]]=x; for(int i=0;i=0;i--){ qqq &qc=qrys[i]; if(qc.tip==1)BIT.add(nstart[0][qc.x],-1); else qc.rez=BIT.get(nend[0][qc.p])-BIT.get(nstart[0][qc.p]-1); } } struct node{ vectorvals; fenwick BIT; node(){ ///printf("NNN %d\n",n+1); vals.pb(0);vals.pb(maxn); } void ubaci(int x){ int pos=lower_bound(vals.begin(),vals.end(),x)-vals.begin(); BIT.add(pos,1); } void ispis(){ for(int i=0;irp || r=lp && r<=rp){ ///printf("%d %d - %d %d | val= %d \n",l,r,lp,rp,tree[x].get(vp)); return tree[x].get(vp); } int mid=(l+r)/2; return qry(x*2,l,mid,lp,rp,vp)+qry(x*2+1,mid+1,r,lp,rp,vp); } vector >>ofq[maxn]; void cepaj(){ for(int i=1;i<=n;i++){ int id=niz[1][i]; upd(1,1,n,nstart[0][id],id); for(int j=0;j