记录编号 392963 评测结果 AAAAAAAAAAAA
题目名称 售票系统 最终得分 100
用户昵称 GravatarkZime 是否通过 通过
代码语言 C++ 运行时间 0.136 s
提交时间 2017-04-09 16:52:53 内存使用 11.00 MiB
显示代码纯文本
#include <iostream> 
#include <cstdio>
#define MAXN 70000
using namespace std;

inline void File_read() {
#ifndef MYLAB
	freopen("railway.in", "r", stdin);
	freopen("railway.out", "w", stdout);
#else
	freopen("in.txt", "r", stdin);
#endif
}

struct segtree{
	int l;
	int r; 
	int es;//the cnt of empty seat
	int lt; //1 is full, 0 is empty 
	inline segtree(){;} 
	inline segtree(int l_, int r_, int es_) {
		l = l_;
		r = r_;
		es = es_;
		lt = -1;
	}
}nd[MAXN * 10 + 100];

int c, s, r;

inline int get_num() {
	int k = 0; 
	char c = getchar();
	for(;!isdigit(c); c = getchar());
	for(; isdigit(c); c = getchar()) {
		k = k * 10 + c - '0';
	}
	return k;
}

void build(int now, int l, int r) {
	nd[now] = segtree(l, r, s); 
	if(l == r) return;
	build(now << 1, l, (l + r) / 2);
	build(now << 1 | 1, (l + r) / 2 + 1, r);
}

inline void pushdown(int now) {
	if(nd[now].lt != -1) {
		nd[now].es -= nd[now].lt;
		if(nd[now << 1].lt == -1) nd[now << 1].lt = nd[now].lt;
		else nd[now << 1].lt += nd[now].lt;
		if(nd[now << 1 | 1].lt == -1) nd[now << 1 | 1].lt = nd[now].lt;
		else nd[now << 1 | 1].lt += nd[now].lt;
	}//full seat
	nd[now].lt = -1;
}

inline void pushup(int now) {
	while(nd[now >> 1].es > nd[now].es) {
		nd[now >> 1].es = nd[now].es;
		now = now >> 1;
	}
}

int check_seat(int now,int l, int r) {
	pushdown(now);
	if(nd[now].l == l && nd[now].r == r) {
		int tmp = nd[now].es;
		return tmp; 
	}
	else if(nd[now << 1].r >= r) {
		int tmp = check_seat(now << 1, l, r);
		return tmp;
	}
	else if(nd[now << 1 | 1].l <= l) {
		int tmp = check_seat(now << 1 | 1, l, r);
		return tmp;
	}
	else {
		int tmp1 = check_seat(now << 1, l, nd[now << 1].r);
		int tmp2 = check_seat(now << 1 | 1, nd[now << 1 | 1].l, r);
		return min(tmp1, tmp2);
	}
}



void update(int now, int l, int r, int n) {
	pushdown(now);
	if(nd[now].l == l && nd[now].r == r) {
		nd[now].lt = n;
		pushdown(now);
		pushup(now);
		return;
	}
	else if(r <= nd[now << 1].r) {
		update(now << 1, l, r, n);
	}
	else if(l >= nd[now << 1 | 1].l) {
		update(now << 1 | 1, l , r, n);
	}
	else {
		update(now << 1, l, nd[now << 1].r, n);
		update(now << 1 | 1, nd[now << 1 | 1].l, r, n);
	}
}

int main() {
	File_read(); 
	c = get_num();
	s = get_num();
	r = get_num();
	build(1, 1, c - 1);	
	while (r--) {
		int u = get_num();
		int v = get_num();
		int n = get_num();
		if(check_seat(1, u, v - 1) >= n) {
			printf("YES\n");
			update(1, u, v - 1, n);
		} else {
			printf("NO\n");
		}
	}
}