[bzoj4592] [Shoi2015] Brain cavity treatment instrument

Source: Internet
Author: User

The surface cannot look straight into the series.

The line of the tree.

The operations involved are: Interval assignment of 0, calculate the number of 1 in the interval, interval assignment is 1, the maximum number of consecutive 1 in the interval.

1#include <cstdio>2#include <iostream>3#include <cstring>4 using namespacestd;5 Const intmaxn=200233,mxnode=maxn<<1;6 intLc[mxnode],rc[mxnode],sz[mxnode],num0[mxnode],mxl0[mxnode],mxr0[mxnode],mx0[mxnode],tot;7 intTag[mxnode];8 intI,j,k,n,m,l,r,mxr,num,ans;9 BOOLFirst ;Ten   One intRaCharRx; AInlineintRead () { -Rx=getchar (), ra=0; -      while(rx<'0'|| Rx>'9') rx=GetChar (); the      while(rx>='0'&&rx<='9') ra*=Ten, ra+=rx- -, Rx=getchar ();returnRA; - } -   -InlineintMaxintAintb) {returnA>b?a:b;} +InlinevoidUpdintXintLintR) { -num0[x]=num0[l]+Num0[r], +mxl0[x]=mxl0[l],mxr0[x]=Mxr0[r]; A     if(Mxl0[l]==sz[l]) mxl0[x]+=Mxl0[r]; at     if(Mxr0[r]==sz[r]) mxr0[x]+=Mxr0[l]; -Mx0[x]=max (Max (Mx0[l],mx0[r]), mxr0[l]+mxl0[r]); - } -InlinevoidPushdown (intx) { -     if(tag[x]==-1)return; -     intL=lc[x],r=Rc[x]; in     if(tag[x]==0) -tag[l]=tag[r]=0, tomx0[l]=mxl0[l]=mxr0[l]=num0[l]=Sz[l], +mx0[r]=mxl0[r]=mxr0[r]=num0[r]=Sz[r]; -     Else thetag[l]=tag[r]=1, *mx0[l]=mxl0[l]=mxr0[l]=num0[l]=0, $mx0[r]=mxl0[r]=mxr0[r]=num0[r]=0;Panax Notoginsengtag[x]=-1; - } the voidBuildintAintb) { +     intx=++tot; Asz[x]=b-a+1, tag[x]=-1; the     if(a==b)return; +     intMid=a+b>>1; -lc[x]=tot+1, build (A,mid), rc[x]=tot+1, Build (mid+1, b); $ } $ voidCover0 (intXintAintb) { -     if(Num0[x]==sz[x])return; -     if(l<=a&&r>=b) { thetag[x]=0, -mx0[x]=mxl0[x]=mxr0[x]=num0[x]=Sz[x];Wuyi         return; the     } - pushdown (x); Wu     intMid=a+b>>1; -     if(l<=mid) Cover0 (LC[X],A,MID); About     if(R>mid) Cover0 (rc[x],mid+1, b); $ upd (x,lc[x],rc[x]); - } - voidGet1 (intXintAintb) { -     if(Num0[x]==sz[x])return; A     if(l<=a&&r>=b) { +num+=sz[x]-Num0[x], thetag[x]=0, -mx0[x]=mxl0[x]=mxr0[x]=num0[x]=Sz[x]; $         return; the     } the pushdown (x); the     intMid=a+b>>1; the     if(l<=mid) Get1 (LC[X],A,MID); -     if(R>mid) Get1 (rc[x],mid+1, b); in upd (x,lc[x],rc[x]); the } the voidTreatintXintAintb) { About     if(!num0[x]| |! NUM)return; the     if(l<=a&&r>=b&&num0[x]<=NUM) { thenum-=num0[x],tag[x]=1, themx0[x]=mxl0[x]=mxr0[x]=num0[x]=0; +         return; -     } the pushdown (x);Bayi     intMid=a+b>>1; the     if(l<=mid) Treat (LC[X],A,MID); the     if(R>mid) Treat (rc[x],mid+1, b); - upd (x,lc[x],rc[x]); - } the voidQueryintXintAintb) { the     if(l<=a&&r>=b) { the         if(first) ans=mx0[x],mxr=mxr0[x],first=0; the         Else{ -Ans=max (Ans,max (mxr+mxl0[x],mx0[x])); the             if(Num0[x]==sz[x]) MXR+=SZ[X];ElseMxr=Mxr0[x]; the         } the         return;94     } the pushdown (x); the     intMid=a+b>>1; the     if(l<=mid) query (LC[X],A,MID);98     if(r>mid) query (rc[x],mid+1, b); About } - intMain () {101N=read (), m=read ();102Build1, n);intid,x,y,x1,y1;103      while(m--){104Id=read (), X=read (), y=read (); the         if(id==0) L=x,r=y,cover0 (1,1, n);//, printf ("num0:%d mxl0:%d mxr0:%d\n", num0[1],mxl0[1],mxr0[1]);106         if(id==1){107X1=read (), Y1=read (), num=0, L=x,r=y,get1 (1,1, n);108L=x1,r=y1,treat (1,1, n);109         } the         if(id==2)111l=x,r=y,first=1, ans=0, Query (1,1, n), printf ("%d\n", ans); the     }113     return 0; the}
View Code

[bzoj4592] [Shoi2015] Brain cavity treatment 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.