BZOJ 1135: [POI2009]Lyz

首先是二分图匹配

Hall定理

令a[i]表示尺码为i的人有多少个

然后是任何的l,r  a[i]之和<=(r-l+1+d)*k

->任何的l,r (a[i]-k)之和<=d*k(定值)

线段树维护最大子段和

#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,k,d;
long long tree_sum[800005],tree_max[800005],tree_maxl[800005],tree_maxr[800005];
void update(int t){
	tree_sum[t]=tree_sum[t<<1]+tree_sum[t<<1|1];
	tree_maxl[t]=max(tree_maxl[t<<1],tree_maxl[t<<1|1]+tree_sum[t<<1]);
	tree_maxr[t]=max(tree_maxr[t<<1|1],tree_maxr[t<<1]+tree_sum[t<<1|1]);
	tree_max[t]=max(tree_max[t<<1],tree_max[t<<1|1]);
	tree_max[t]=max(tree_max[t],tree_maxr[t<<1]+tree_maxl[t<<1|1]);
}
void build(int t,int l,int r){
	if (l==r){
		tree_max[t]=tree_maxl[t]=tree_maxr[t]=tree_sum[t]=-k;
		return;
	}
	int mid=(l+r)>>1;
	build(t<<1,l,mid);
	build(t<<1|1,mid+1,r);
	update(t);
}
void modify(int t,int l,int r,int x,int y){
	if (l==r){
		tree_max[t]+=y;
		tree_maxl[t]+=y;
		tree_maxr[t]+=y;
		tree_sum[t]+=y;
		return;
	}
	int mid=(l+r)>>1;
	if (x<=mid) modify(t<<1,l,mid,x,y);
	else modify(t<<1|1,mid+1,r,x,y);
	update(t);
}
int main(){
	scanf("%d%d%d%d",&n,&m,&k,&d);
	build(1,1,n);
	for (int i=1; i<=m; i++){
		int x,y;
		scanf("%d%d",&x,&y);
		modify(1,1,n,x,y);
		if (tree_max[1]<=1ll*d*k) printf("TAK\n");
		else printf("NIE\n");
	}
	return 0;
}

  

posted @ 2018-11-05 18:39  ~Silent  阅读(177)  评论(0编辑  收藏  举报
Live2D