记录编号 |
433855 |
评测结果 |
AAAAAAAAAAAA |
题目名称 |
售票系统 |
最终得分 |
100 |
用户昵称 |
HeHe |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.099 s |
提交时间 |
2017-08-06 13:13:55 |
内存使用 |
0.82 MiB |
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
inline char getc(void) {
static char buf[1 << 18], *fs, *ft;
return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 18, stdin)), fs == ft) ? EOF : *fs++;
}
inline int read(void) {
register int res = 0;
register char tmp = getc();
while(!isdigit(tmp)) tmp = getc();
while(isdigit(tmp))
res = ((res + (res << 2)) << 1) + (tmp ^ 0x30),
tmp = getc();
return res;
}
char ops[1 << 18], *opt = ops, *const opt_end = ops + (1 << 18);
inline void write_all(void) {
fwrite(ops, 1, opt - ops, stdout);
opt = ops; return ;
}
inline void write(const char *str) {
while(*str) {
*(opt++) = *(str++);
if(opt == opt_end) write_all();
}
return ;
}
struct NODE{
int val, tag;
NODE *ls, *rs;
NODE(int S) {
ls = rs = NULL;
tag = 0, val = S;
}
};
NODE *Build(int l, int r);
int Query(NODE *node, int l, int r, int L, int R);
void update(NODE *node, int l, int r, int k, int L, int R);
int C, S, R;
int O, D, N;
NODE *root;
int main() {
#ifndef LOCAL
freopen("railway.in", "r", stdin);
freopen("railway.out", "w", stdout);
#endif
C = read(), S = read(), R = read();
root = Build(1, C);
for(int i = 0; i < R; ++i) {
O = read(), D = read(), N = read();
int tmp = Query(root, O, D - 1, 1, C);
if(N > tmp) write("NO\n");
else {
write("YES\n");
update(root, O, D - 1, N, 1, C);
}
}
write_all();
return 0;
}
NODE *Build(int l, int r) {
register NODE *p = new NODE(S);
if(l ^ r) {
register int mid = (l + r) >> 1;
p->ls = Build(l, mid);
p->rs = Build(mid + 1, r);
}
return p;
}
int Query(NODE *node, int l, int r, int L, int R) {
if(l == L && r == R) return node->val;
if(node->ls) {
node->ls->tag += node->tag;
node->rs->tag += node->tag;
node->ls->val -= node->tag;
node->rs->val -= node->tag;
}
node->tag = 0;
register int mid = (L + R) >> 1;
if(r <= mid) return Query(node->ls, l, r, L, mid);
if(mid < l) return Query(node->rs, l, r, mid + 1, R);
return min(Query(node->ls, l, mid, L, mid), Query(node->rs, mid + 1, r, mid + 1, R));
}
void update(NODE *node, int l, int r, int k, int L, int R) {
if(l == L && r == R) {
node->val -= k;
node->tag += k;
return ;
}
register int mid = (L + R) >> 1;
if(r <= mid) {
update(node->ls, l, r, k, L, mid);
node->val = min(node->ls->val, node->rs->val);
} else if(mid < l) {
update(node->rs, l, r, k, mid + 1, R);
node->val = min(node->ls->val, node->rs->val);
} else {
update(node->ls, l, mid, k, L, mid);
update(node->rs, mid + 1, r, k, mid + 1, R);
node->val = min(node->ls->val, node->rs->val);
}
return ;
}