Exercises
Discretization + line tree, pay attention to the relationship between several types of markers.
1#include <cstdio>2#include <cstring>3#include <algorithm>4 #defineLL Long Long5 #defineRG Register6 #defineN 2000107 #defineLS (u<<1)8 #defineRS (u<<1|1)9 #defineMid ((A[U].L+A[U].R) >>1)Ten #defineINF (1e18+1) One using namespacestd; A intN,m,tot,type[n]; - LL L[n],r[n],b[n]; - structtree{ the LL L,r,p0,p1,tag; -}a[n<<3]; - inline LL Read () { -LL k=0, f=1;CharC=GetChar (); + while(c<'0'|| C>'9') c=='-'&& (f=-1), c=GetChar (); - while('0'<=c&&c<='9') k=k*Ten+c-'0', c=GetChar (); + returnk*F; A } at voidBuildintUintLintR) { -A[u].l=l; A[u].r=r; A[u].p0=l; a[u].p1=inf; - if(l<R) { -Build (Ls,l,mid); Build (rs,mid+1, R); - } - } inInlinevoidPushup (intu) { -a[u].p0=min (a[ls].p0,a[rs].p0); toa[u].p1=min (a[ls].p1,a[rs].p1); + } - voidPushdown (intu) { the if(a[u].tag==1){ *a[ls].p0=a[rs].p0=inf; $A[LS].P1=A[LS].L; a[rs].p1=A[RS].L;Panax Notoginseng } - Else if(a[u].tag==2){ thea[ls].p1=a[rs].p1=inf; +A[LS].P0=A[LS].L; a[rs].p0=A[RS].L; A } the Else{ + swap (A[LS].P0,A[LS].P1); - swap (A[RS].P0,A[RS].P1); $ } $ if(a[u].tag==3){ - if(a[ls].tag==1) a[ls].tag=2; - Else if(a[ls].tag==2) a[ls].tag=1; the Else if(a[ls].tag==3) a[ls].tag=0; - Elsea[ls].tag=3;Wuyi if(a[rs].tag==1) a[rs].tag=2; the Else if(a[rs].tag==2) a[rs].tag=1; - Else if(a[rs].tag==3) a[rs].tag=0; Wu Elsea[rs].tag=3; - } About Elsea[ls].tag=a[rs].tag=A[u].tag; $a[u].tag=0; - } - voidUpdateintUintLintRinttype) { - if(l<=a[u].l&&a[u].r<=R) { A if(type==1) a[u].p0=inf,a[u].p1=A[U].L; + Else if(type==2) a[u].p0=a[u].l,a[u].p1=inf; the Elseswap (A[U].P0,A[U].P1); - if(type==3){ $ if(a[u].tag==1) a[u].tag=2; the Else if(a[u].tag==2) a[u].tag=1; the Else if(a[u].tag==3) a[u].tag=0; the Elsea[u].tag=3; the } - Elsea[u].tag=type; in return; the } the if(A[u].tag) pushdown (u); About if(l<=mid) Update (LS,L,R,TYPE); the if(r>mid) Update (RS,L,R,TYPE); thea[u].p0=min (a[ls].p0,a[rs].p0); thea[u].p1=min (a[ls].p1,a[rs].p1); + } - intQueryintUintPOS) { the if(A[U].L==A[U].R)returna[u].p0;Bayi if(A[u].tag) pushdown (u); the if(Pos<=mid)returnquery (ls,pos); the Else returnquery (rs,pos); - } - intMain () { theM=read (); b[tot=1]=1; the for(RGintI=1; i<=m;i++){ theType[i]=read (); L[i]=b[++tot]=read (); R[i]=b[++tot]=read () +1; the } -Sort (b +1, B +1+tot); N=unique (b +1, B +1+tot)-b-1; the for(RGintI=1; i<=m;i++) theL[i]=lower_bound (b +1, B +1+n,l[i])-B, theR[i]=lower_bound (b +1, B +1+n,r[i])-b;94Build1,1, n); the for(RGintI=1; i<=m;i++){ theUpdate1, l[i],r[i]-1, Type[i]); theLL tmp=a[1].p0;98 if(Tmp==inf) tmp=b[n]+1; About Elsetmp=b[tmp]; -printf"%lld\n", TMP);101 }102 return 0;103}
Codeforces 817F MEX Queries