Topic links
Test instructions: Start with a blank interval, each of which may take two actions: A adds an interval of length p to the position of a continuous gap L: One interval restores the blank, and the number of times a cannot be requested.
Very bare line tree topic, with line segment tree statistics the largest white space, each node needs to record the current interval of the longest white space, from the left end of the longest white space, starting from the right end of the longest white space. Push_up the time to discuss, you can take [L,mid] and [Mid+1,r] the largest white space, you can also use [L,mid] from the right end of the longest white space +[mid+1,r] from the left end of the largest white space interval.
Every time a, query the current can be installed in the white space of the most left (with a global variable ans statistics), if the root node of the longest white space >=p, the [ans,ans+p-1] into the state of being occupied, or in the answer + +; if l, it would be easier. Direct interval modification (I heard that the mark can be better than I do not debug the test room directly explode 0 of the high?) )。 The bottom of the tag is basic (it must be that the current node has been modified and the sub-range has not been modified).
1#include <iostream>2#include <cstring>3#include <cstdio>4 #defineL i<<15 #defineR i<<1|16 #defineMid (X+y)/27 #defineLson X,mid8 #defineRson Mid+1,y9 using namespacestd;Ten Const intinf=0x7fffffff; One Const intn=500005; A structhp{intW,p,li,ri,size,delta;} a[n<<2]; - intans; -Inlineint inch() the{intx=0;CharCh=getchar (); while(ch<'0'|| Ch>'9') ch=GetChar (); - while(ch>='0'&&ch<='9') x=x*Ten+ch-'0', Ch=getchar ();returnx;} -Inlineint Get(){CharCh=getchar (); while(ch!='A'&&ch!='L') Ch=getchar ();returnch=='A';} - voidBuildintIintXinty) +{a[i]= (HP) {y-x+1, x,y-x+1, y-x+1, y-x+1,-1}; - if(x==y)return; build (L,lson); build (R,rson) ; + } A voidPushdown (intIintXinty) at{intC=a[i].delta; a[i].delta=-1; a[l].delta=a[r].delta=C; - if(c) {a[l].w=a[l].li=a[l].ri=0, a[l].p=inf;a[r].w=a[r].li=a[r].ri=0, a[r].p=inf;} - Else{a[l].w=a[l].li=a[l].ri=mid-x+1, a[l].p=x;a[r].w=a[r].li=a[r].ri=y-mid,a[r].p=mid+1;} - } -Inline HP Updata (HP A,HP B,intXinty) -{HP C; c.delta=-1; c.size=a.size+b.size; in if(! A.W) c.w=b.w,c.li=0, c.ri=b.ri,c.p=B.P; - Else if(! B.W) c.w=a.w,c.li=a.li,c.ri=0, c.p=A.P; to Else{c.li=a.li+ (a.li==a.size? B.li:0); +c.ri=b.ri+ (b.ri==b.size? A.ri:0); - if(A.W>=B.W) c.w=a.w,c.p=A.P; the Elsec.w=b.w,c.p=B.P; * if(a.ri+b.li>c.w| | (a.ri+b.li==c.w&&mid-a.ri+1<C.P)) $c.w=a.ri+b.li,c.p=mid-a.ri+1;Panax Notoginseng}returnC; - } the voidInsertintIintXintYintSintTintk) +{if(x>=s&&y<=t) A{if(k) a[i]= (HP) {0Inf0,0, y-x+1,1}; the Elsea[i]= (HP) {y-x+1, x,y-x+1, y-x+1, y-x+1,0};return;} + if(a[i].delta!=-1) pushdown (i,x,y); - if(s<=mid) Insert (L,LSON,S,T,K);if(t>mid) Insert (R,RSON,S,T,K); $a[i]=Updata (a[l],a[r],x,y); $ } - voidQueryintIintXintYintk) { - if(x==y) {ans=x;return;} the if(a[i].delta!=-1) pushdown (i,x,y); - if(a[l].w>=k) query (l,lson,k);Wuyi Else if(a[l].ri+a[r].li>=k) { theans=mid-a[l].ri+1; - return; Wu}Elsequery (r,rson,k); - } About intMain () ${intn=inch(), m=inch(); -Build1,1, n);inttot=0; - while(m--) -{intopt=Get(); A if(opt) +{intx=inch();if(!x)Continue; the if(a[1].W<X) tot++; - Else{Query (1,1, n,x); $Insert1,1, n,ans,ans+x-1,1); the }} the Else{intx=inch(), y=inch(); Insert (1,1, N,x,y,0);} the the } -cout<<tot<<Endl; in}
AC Code
The ability to debug needs to be improved.
Bzoj 3050: [Usaco2013 jan]seating (Line tree bare topic, but the interval modification tag is decentralized and discussed push_up very worried)