4592: [Shoi2015] brain cavity therapeutic instrument Time limit:20 Sec Memory limit:256 MB
submit:69 solved:38
[Submit] [Status] [Discuss] Description, inventor of the auto-brush machine, SHTSC unveiled his new invention: the brain-hole healer-a mysterious device that could heal his growing brain hole because of his invention. For the sake of simplicity, we see the brain as a 01 sequence. 1 for the brain tissue in this position, 0 means it's a brain hole. 1010001110 The basic principle of repairing a piece of brain cavity is to dig up another contiguous area and fill the brain cavity with the normal working brain tissue. (So the brain cavity therapy instrument is the brain cavity of the treatment instrument?) For example, use the above position 8th to position 10th to fix the brain hole at position 1th to position 4th. We will get: 1111001000 If you use position 1th to position 4th, fix the 8th position to the 10th position: 0000001111 This is because the brain cavity treatment device will throw away the extra brain tissue. If you use position 7th to position 10th, fill the 1th position to the 6th position: 1111000000 This is because if there are not enough brain tissue dug up in the new brain hole, the brain cavity treatment instrument will only try to fill the anterior brain hole. Assuming the initial SHTSC does not have a brain cavity, giving some sequence of operations for digging a brain hole and a brain cavity, you need to answer the SHTSC question immediately: How big is the largest contiguous brain cavity in a certain interval of the brain. Input the first row of two integer n,m. The brain that represents SHTSC can be divided into n contiguous regions numbered from 1 to N. There is a M operation. Each row of the following m lines is one of the following three formats. 0 L R:SHTSC dug a brain hole from L to R. 1 l0 r0 L1 R2:SHTSC was treated with a brain-hole treatment, using a brain tissue from l0 to r0 to repair L1 to R1 's brain cavity. 2 L R:SHTSC Ask me how big the largest brain hole is in the range L to R. N,m <=200000,1<=l<=r<=noutput for each query, the output line is an integer that indicates how large the maximum contiguous brain cavity area is in the query interval. Sample Input10 10
0 2 2
0 4 6
0 10 10
2 1 10
1 8 10) 1 4
2 1 10
1 1 4) 8 10
2 1 10
1 7 10) 1 6
2 1 10
Sample Output3
3
6
6
Hintsource
by anonymous upload
Solution
Line tree maintenance interval continuous stuff ....
Maintain the left and right end of the merger when the attention can be, for the brain hole operation, two points, you can
Code
#include <iostream>#include<cstring>#include<cstdio>#include<cmath>#include<algorithm>using namespaceStd;inlineintRead () {intx=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9') {if(ch=='-') f=-1; Ch=GetChar ();} while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; Ch=GetChar ();} returnx*F;}#defineMAXN 210000intn,m;structtreenode{intL,r,size,len,lx,rx,tag,ans;} tree[maxn<<2]; TreeNode Merge (TreeNode x,treenode y) {TreeNode re; RE.L=x.l,re.r=y.r,re.len=x.len+y.len,re.size=re.r-re.l+1; if(x.len==x.size) Re.lx=x.len+y.lx;Elsere.lx=X.LX; if(y.len==y.size) Re.rx=y.len+x.rx;Elsere.rx=Y.rx; Re.ans=max (Max (X.ans,y.ans), X.RX+Y.LX); re.tag=-1; returnre;} InlinevoidUpDate (intNow) {Tree[now]=merge (tree[now<<1],tree[now<<1|1]);}voidBuildtree (intNowintLintR) {TREE[NOW].L=l,tree[now].r=r,tree[now].size=r-l+1, tree[now].tag=-1; TREE[NOW].LX=tree[now].rx=tree[now].ans=tree[now].len=0; if(L==R)return; intMid= (l+r) >>1; Buildtree ( now<<1, L,mid); Buildtree (now<<1|1, mid+1, R);//UpDate (now);}inlinevoidPaint (intNowintc) { if(c==1) tree[now].lx=tree[now].rx=tree[now].ans=tree[now].len=0; Elsetree[now].lx=tree[now].rx=tree[now].ans=tree[now].len=tree[now].size; Tree[now].tag=C;} InlinevoidPushdown (intNow ) { if(tree[now].tag==-1)return; Paint ( now<<1, Tree[now].tag); Paint (now<<1|1, Tree[now].tag); Tree[now].tag=-1;}voidDisposalhole (intNowintLintRintdeal) { if(L<=TREE[NOW].L && R>=TREE[NOW].R) {Paint (now,deal);return;} Pushdown (now); intMid= (TREE[NOW].L+TREE[NOW].R) >>1; if(L<=mid) Disposalhole (now<<1, L,r,deal); if(R>mid) Disposalhole (now<<1|1, L,r,deal); UpDate (now);}intLength (intNowintLintR) { if(L<=TREE[NOW].L && R>=TREE[NOW].R)returnTree[now].len; Pushdown (now); intMid= (TREE[NOW].L+TREE[NOW].R) >>1, re=0; if(L<=mid) Re+=length (now<<1, L,r); if(R>mid) Re+=length (now<<1|1, L,r); returnre; }voidFillhole (intNowintLintRintCNT) { if(cnt==0)return; if(L<=TREE[NOW].L && R>=TREE[NOW].R && tree[now].len<=cnt) {Paint (now,1);return;} Pushdown (now); intMid= (TREE[NOW].L+TREE[NOW].R) >>1, Len; if(l<=mid)if((Len=length (now<<1, L,r)) <CNT) {Disposalhole ( now<<1, L,r,1);if(R>mid) Fillhole (now<<1|1, l,r,cnt-len);} ElseFillhole (now<<1, l,r,cnt); ElseFillhole (now<<1|1, l,r,cnt); UpDate (now);} TreeNode Query (intNowintLintR) { if(L<=TREE[NOW].L && R>=TREE[NOW].R)returnTree[now]; Pushdown (now); intMid= (TREE[NOW].L+TREE[NOW].R) >>1; if(R<=mid)returnQuery (now<<1, L,r); Else if(L>mid)returnQuery (now<<1|1, L,r); Else returnMerge (Query (now<<1, L,r), Query (now<<1|1, L,r));}intMain () {n=read (); m=read (); Buildtree (1,1, N); for(intI=1; i<=m; i++) { intOpt=read ();intL,r,l,r,cnt=0; Switch(opt) { Case 0: L=read (), R=read (); Disposalhole (1, L,r,0); Break; Case 1: L=read (), R=read (), L=read (), R=read (), cnt=r-l+1-length (1, l,r); Disposalhole (1, L,r,0); Fillhole (1, l,r,cnt); Break; Case 2: L=read (), R=read (); printf"%d\n", Query (1, L,r). ans); Break; } } return 0;}
Small non-privileged running fast, straight Rank3
Large permissions by the small card rank4, anger plus inline, run more slowly ...
"BZOJ-4592" Brain hole therapeutic Instrument segment tree