比赛 Segment Tree Competition 评测结果 RRRRRRRRR
题目名称 滑动窗口 最终得分 0
用户昵称 NewBee 运行时间 0.015 s
代码语言 C++ 内存使用 2.12 MiB
提交时间 2016-08-28 19:03:06
显示代码纯文本
#include<cstdio>
#define Cu fclose(stdin);fclose(stdout);return 0;
#define Begin freopen("railway.in","r",stdin);freopen("railway.out","w",stdout);chul();Cu
using namespace std;
//designed by New_Beeؼ 
const int maxn=60010;
struct op{
	int lazy,sold;
	op(){
		lazy=sold=0;
	}
};
op line[maxn<<2];
int s,t,l,r,c,se,k;
int max(int,int);
int find(int);
void adds(int,int);
void cleanlazy(int);
void chul();
int main(){
	Begin
}
void chul(){
	scanf("%d%d%d",&c,&se,&k);c--;
	int f,to,ti,ans;
	for(int i=1;i<=k;i++){	
		scanf("%d%d%d",&f,&to,&ti);
		to--;
		s=f;t=to;l=1;r=c;
		ans=find(1);
		if(ans+ti<=se){
			printf("YES\n");
			l=1,r=c;
			adds(1,ti);
			continue;
		}
		printf("NO\n");
	}
}
void adds(int rt,int ti){
	if(s<=l&&r<=t){
		line[rt].sold+=ti;
		line[rt].lazy+=ti;
		return;
	}
	int mid=(l+r)>>1;
	int tim=r;
	if(s<=mid){
		r=mid;
		adds(rt<<1,ti);
	}
	if(t>mid){
		l=mid+1;r=tim;
		adds(rt<<1|1,ti);
	}
	line[rt].sold=max(line[rt<<1].sold,line[rt<<1|1].sold);
}
int find(int rt){
	if(s<=l&&r<=t)return line[rt].sold;
	int mid=(l+r)>>1;
	cleanlazy(rt);
	if(s>mid){
		l=mid+1;
		return find(rt<<1|1);
	}
	else if(t<=mid){
		r=mid;
		return find(rt<<1);
	}
	else{
		int tim=r;
		r=mid;
		int x=find(rt<<1);
		l=mid+1;r=tim;
		int y=find(rt<<1|1);
		return max(x,y);
	}
}
void cleanlazy(int rt){
	if(line[rt].lazy==0)return;
	line[rt<<1].lazy+=line[rt].lazy;
	line[rt<<1|1].lazy+=line[rt].lazy;
	line[rt<<1].sold+=line[rt].lazy;
	line[rt<<1|1].sold+=line[rt].lazy;
	line[rt].lazy=0;
}
int max(int x,int y){
	if(x>y)return x;
	return y;
}