bzoj4592 [Shoi2015] brain hole therapy instrument

Source: Internet
Author: User

Descriptioninventor Shtsc, who invented the auto-brush machine, also disclosed his new invention: the brain-cavity therapeutic apparatus, 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. 1 0 1 0 0 0 1 1 1 0the 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:1 1 1 1 0 0 1 0 0 0If you use position 1th to position 4th, fix the 8th position to position 10th:0 0 0 0 0 0 1 1 1 1 This is because the brain cavity treatment device will throw away the extra brain tissue. If you use position 7th to position number 10th to fill the 1th position to position 6th:1 1 1 1 0 0 0 0 0 0This 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 that the initial SHTSC does not have a brain cavity, giving some sequence of operations for digging the brain and brain cavities, you need to answer the SHTSC question immediately:How large is the largest contiguous brain cavity in a certain interval of the brain. InputThe first row of two integers 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<=nOutputfor each query, the output line is an integer that indicates how large the maximum contiguous brain cavity area is in the query interval. Segment Tree Maintenance interval information: 0 consecutive numbers of intervals from the left
Interval from the right start continuous 0 number interval continuous 0 of the maximum length interval 0 of the number of interval length interval 0/1 covered by the tag support operation: Interval coverage 0/1 query interval 1 Number of query interval the longest continuous 0 length
#include <cstdio>inlineintinput () {intx=0, c=GetChar ();  while(c> $|| c< -) c=GetChar ();  while(c> -&&c< -) x=x*Ten+c- -, c=GetChar (); returnx;}Const intn=420000;intN,m,l,r;intc0[n],sz[n],lc[n],rc[n],f1[n],f0[n],ls[n],rs[n],ms[n],p=1, ans=0, Pv,ptr;inlineintMaxintAintb) {returnA>b?a:b;} InlinevoidMAXS (int&a,intb) {if(a<b) a=b;}intBuildintLintR) {    intw=p++; if(l<R) {        intM=l+r>>1; LC[W]=build (L,M); RC[W]=build (m+1, R); SZ[W]=sz[lc[w]]+Sz[rc[w]]; }Elsesz[w]=1; returnW;} InlinevoidTAG1 (intW) {    if(!W)return; F1[W]=1; f0[w]=0; C0[W]=ls[w]=rs[w]=ms[w]=0;} InlinevoidTAG0 (intW) {    if(!W)return; F1[W]=0; f0[w]=1; C0[W]=ls[w]=rs[w]=ms[w]=sz[w];} InlinevoidUpintW) {    intL=lc[w],r=Rc[w]; MS[W]=Max (Ms[l],ms[r]); Maxs (Ms[w],rs[l]+Ls[r]); LS[W]=Ls[l]; RS[W]=Rs[r]; if(Ls[l]==sz[l]) maxs (ls[w],ls[l]+Ls[r]); if(Rs[r]==sz[r]) maxs (rs[w],rs[l]+Rs[r]); C0[W]=c0[l]+C0[r]; SZ[W]=sz[l]+sz[r];} InlinevoidDwnintW) {    if(F1[w]) {F1[w]=0;    Tag1 (Lc[w]); Tag1 (Rc[w]); }    if(F0[w]) {F0[w]=0;    TAG0 (Lc[w]); Tag0 (Rc[w]); }}voidSet0 (intw=1,intL=1,intR=N) {    if(l<=l&&r<=R)        {tag0 (w); return;    } dwn (W); intM=l+r>>1; if(l<=M) set0 (lc[w],l,m); if(r>m) Set0 (rc[w],m+1, R); Up (w);}voidGet1 (intw=1,intL=1,intR=N) {    if(l<=l&&r<=R) {ans+=sz[w]-C0[w]; return;    } dwn (W); intM=l+r>>1; if(l<=M) Get1 (lc[w],l,m); if(r>m) Get1 (rc[w],m+1, R);}voidSet1 (intw=1,intL=1,intR=N) {    if(!ans)return; if(l<=l&&r<=r&&c0[w]<=ans) {ans-=C0[w];        Tag1 (w); return;    } dwn (W); intM=l+r>>1; if(l<=M) Set1 (lc[w],l,m); if(r>m) Set1 (rc[w],m+1, R); Up (w);}voidQueryintw=1,intL=1,intR=N) {    if(l<=l&&r<=R) {        if(PV) {Lc[ptr]=pv;rc[ptr]=W;            Up (PTR); PV=ptr++; }Elsepv=W; return;    } dwn (W); intM=l+r>>1; if(l<=M) query (LC[W],L,M); if(r>m) query (rc[w],m+1, R);}intMain () {n=input (); m=input (); Build (1, N);  while(m--){        intop=input (); L=input (), r=input (); if(op==0) {set0 (); }Else if(op==1) {ans=0;            Get1 ();            Set0 (); L=input (), r=input ();        Set1 (); }Else{PV=0, ptr=p;            Query (); printf ("%d\n", MS[PV]); }    }    return 0;}

bzoj4592 [Shoi2015] brain hole therapy instrument

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.