比赛 |
区间问题练习 |
评测结果 |
AAAAAAAAAAAA |
题目名称 |
售票系统 |
最终得分 |
100 |
用户昵称 |
Fisher. |
运行时间 |
0.965 s |
代码语言 |
C++ |
内存使用 |
2.15 MiB |
提交时间 |
2017-04-21 18:41:59 |
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <vector>
#include <algorithm>
using namespace std;
struct d
{
int maxx;
int lazy;
};
d node[240040];
int c,s,t;
int nl,nr,w;
void updata(int o,int l,int r)
{
//if(l>nr||r<nl)return;
if(l>=nl&&r<=nr)
{
node[o].maxx+=w;
node[o].lazy+=w;
//cout<<o<<endl;
return;
}
if(node[o].lazy){
node[o*2].maxx+=node[o].lazy;
node[o*2+1].maxx+=node[o].lazy;
node[o*2].lazy+=node[o].lazy;
node[o*2+1].lazy+=node[o].lazy;
node[o].lazy=0;
}
int m=(l+r)/2;
if(m>=nl)
updata(o*2,l,m);
if(m<nr)
updata(o*2+1,m+1,r);
node[o].maxx=max(node[o*2].maxx,node[o*2+1].maxx);
}
int find(int o,int l,int r)
{
//if(l>nr||r<nl)return -1;
if(l>=nl&&r<=nr)
{
// cout<<o<<endl;
return node[o].maxx;
}
if(node[o].lazy){
node[o*2].maxx+=node[o].lazy;
node[o*2+1].maxx+=node[o].lazy;
node[o*2].lazy+=node[o].lazy;
node[o*2+1].lazy+=node[o].lazy;
node[o].lazy=0;
}
int m=(l+r)/2;
int ans=-0x7fffffff;
if(nl<=m)
ans=max(ans,find(o*2,l,m));
if(nr>m)
ans=max(ans,find(o*2+1,m+1,r));
return ans;
}
int main()
{
freopen("railway.in","r",stdin);
freopen("railway.out","w",stdout);
cin>>c>>s>>t;
while(t--)
{
cin>>nl>>nr>>w;
nr--;
int q=find(1,1,c);
//cout<<nl<<" "<<nr<<" "<<q<<endl;
if(q+w>s)cout<<"NO"<<endl;
else
{
updata(1,1,c);
cout<<"YES"<<endl;
}
}
return 0;
}