BZOJ4592 [Shoi2015] brain-hole therapeutic instrument _bzoj

Source: Internet
Author: User

Treatment is actually equivalent to 1 covering a section, the number of original 1 in the interval plus the number of 1 dug out equals the length of the interval, and the length of this interval is the longest for the length of the treatment interval

Record the number of dug out 1, and then climb out of the line in the segment tree, because it is the line of the tree, so find an interval is log

Knowing the length of the interval, how many 1 in the interval, and how many brain tissue there are left, can tell if the interval is completely covered.

Need to determine if there is brain tissue left, if not to return, otherwise the complexity of the wrong

Complexity O (m log n)

#include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <cmath > #include <ctime> #include <algorithm> #include <iomanip> #include <vector> #include <
stack> #include <queue> #include <map> #include <set> #include <bitset> using namespace std;
#define MAXN 200010 #define MAXM 1010 #define LL Long #define INF 1000000000 #define MOD 1000000007 #define EPS 1e-8
int n,m; int s[maxn<<2],mx[maxn<<2],mxl[maxn<<2],mxr[maxn<<2],ch[maxn<<2],s0[maxn<<2
];
int MX,MXR;
int V;
	inline void ud (int x,int y,int z) {int mid=y+z>>1;
	s[x]=s[x<<1]+s[x<<1|1];
	s0[x]=s0[x<<1]+s0[x<<1|1];
	Mx[x]=max (Mxr[x<<1]+mxl[x<<1|1],max (mx[x<<1],mx[x<<1|1));
	mxl[x]=mxl[x<<1];
	mxr[x]=mxr[x<<1|1];
	if (s0[x<<1]==mid-y+1) {mxl[x]=s0[x<<1]+mxl[x<<1|1]; } if (S0[x<<1|1]==z-mid) {mxr[x]=s0[x<<1|1]+mxr[x<<1];
	} inline void Toch (int x,int y,int z,int cv) {s0[x]=mx[x]=mxl[x]=mxr[x]= (z-y+1) * (cv^1);
	s[x]= (z-y+1) *CV;
CH[X]=CV;
		} inline void pd (int x,int y,int z) {if (~ch[x]) {int mid=y+z>>1;
		Toch (X<<1,y,mid,ch[x]);
		Toch (X<<1|1,mid+1,z,ch[x]);
	Ch[x]=-1;
	} void Build (int x,int y,int z) {ch[x]=-1;
		if (y==z) {s0[x]=mx[x]=mxl[x]=mxr[x]=0;
		S[x]=1;
	return;
	} int mid=y+z>>1;
	Build (X<<1,y,mid);
	Build (X<<1|1,mid+1,z);
UD (x,y,z);
		} void Change (int x,int y,int z,int l,int r,int cv) {if (y==l&&z==r) {Toch (X,Y,Z,CV);
	return;
	PD (X,Y,Z);
	int mid=y+z>>1;
	if (r<=mid) {change (X&LT;&LT;1,Y,MID,L,R,CV);
	}else if (l>mid) {change (X&LT;&LT;1|1,MID+1,Z,L,R,CV);
		}else{change (X&LT;&LT;1,Y,MID,L,MID,CV);
	Change (X&LT;&LT;1|1,MID+1,Z,MID+1,R,CV);
} ud (x,y,z);
	int ask (int x,int y,int z,int l,int R) {if (y==l&&z==r) {return s[x];
	PD (X,Y,Z);
	int mid=y+z>>1;
	if (R<=mid) {	Return ask (X&LT;&LT;1,Y,MID,L,R);
	}else if (l>mid) {return ask (X&LT;&LT;1|1,MID+1,Z,L,R);
	}else{return Ask (X<<1,y,mid,l,mid) +ask (x<<1|1,mid+1,z,mid+1,r);
} ud (x,y,z);
		} void Toask (int x,int y,int z,int l,int R) {if (y==l&&z==r) {Mx=max (Mx,max (mxr+mxl[x],mx[x)));
		if (s0[x]==z-y+1) {mxr+=z-y+1;
		}else{Mxr=mxr[x];
	} return;
	PD (X,Y,Z);
	int mid=y+z>>1;
	if (r<=mid) {toask (x<<1,y,mid,l,r);
	}else if (l>mid) {toask (x<<1|1,mid+1,z,l,r);
		}else{Toask (X<<1,y,mid,l,mid);
	Toask (X&LT;&LT;1|1,MID+1,Z,MID+1,R);
} ud (x,y,z);
			} void Dang (int x,int y,int z) {if (y==z) {if (v+s[x]>=z-y+1) {v-=z-y+1-s[x];
		Toch (x,y,z,1);
	} return;
	PD (X,Y,Z);
	int mid=y+z>>1;
		if (v+s[x]>=z-y+1) {v-=z-y+1-s[x];
		Toch (x,y,z,1);
	return;
		}else{Dang (X<<1,y,mid);
		if (V) {dang (x<<1|1,mid+1,z);
} ud (x,y,z); } void Guang (int x,int y,int z,int l,int R) {if (!)
	V) {return; } if (y==l&AMP;&AMP;Z==R) {if (V) {dang (x,y,z);
	} return;
	PD (X,Y,Z);
	int mid=y+z>>1;
	if (R<=mid) {guang (x<<1,y,mid,l,r);
	}else if (l>mid) {guang (x<<1|1,mid+1,z,l,r);
		}else{Guang (X<<1,y,mid,l,mid);
		if (V) {guang (x<<1|1,mid+1,z,mid+1,r);
} ud (x,y,z);
	int main () {int i,o,x,y,xx,yy;
	scanf ("%d%d", &n,&m);
	Build (1,1,n);
		for (i=1;i<=m;i++) {scanf ("%d", &o);
			if (o==0) {scanf ("%d%d", &x,&y);
		Change (1,1,n,x,y,0);
			} if (o==1) {scanf ("%d%d%d%d", &x,&y,&xx,&yy);
			V=ask (1,1,n,x,y);
			Change (1,1,n,x,y,0);
		Guang (1,1,N,XX,YY);
			} if (o==2) {scanf ("%d%d", &x,&y);
			mx=mxr=0;
			Toask (1,1,n,x,y);
		printf ("%d\n", MX);
} return 0;
 }/* 10 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


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.