社区讨论
32分求助
P8856[POI 2002] 火车线路参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @lpnt08ff
- 此快照首次捕获于
- 2023/12/02 16:40 2 年前
- 此快照最后确认于
- 2023/12/02 19:08 2 年前
CPP
#include<bits/stdc++.h>
#define int long long
using namespace std;
int const maxn=60010;
struct node{
int l,r,val,lazy;
}tree[maxn<<3];
int c,s,r;
int o,d,n;
void pushUp(int rt)
{
tree[rt].val=tree[rt<<1].val+tree[rt<<1|1].val;
}
void pushDown(int rt)
{
if(tree[rt].lazy)
{
tree[rt<<1].lazy+=tree[rt].lazy;
tree[rt<<1|1].lazy+=tree[rt].lazy;
tree[rt<<1].val+=tree[rt].lazy;
tree[rt<<1|1].val+=tree[rt].lazy;
tree[rt].lazy=0;
}
}
void build(int l,int r,int rt)
{
tree[rt].l=l;
tree[rt].r=r;
if(l==r)
return;
pushDown(rt);
int mid=l+r>>1;
build(l,mid,rt<<1);
build(mid+1,r,rt<<1|1);
pushUp(rt);
}
void update(int ql,int qr,int x,int rt)
{
int l=tree[rt].l;
int r=tree[rt].r;
if(ql<=l&&r<=qr)
{
tree[rt].lazy+=x;
tree[rt].val+=x;
return;
}
pushDown(rt);
int mid=l+r>>1;
if(ql<=mid)
update(ql,qr,x,rt<<1);
if(qr>mid)
update(ql,qr,x,rt<<1|1);
pushUp(rt);
}
int query(int ql,int qr,int rt)
{
int l=tree[rt].l;
int r=tree[rt].r;
if(ql<=l&&r<=qr)
return tree[rt].val;
pushDown(rt);
int mid=l+r>>1;
int ret=INT_MIN;
if(ql<=mid)
ret=max(ret,query(ql,qr,rt<<1));
if(qr>mid)
ret=max(ret,query(ql,qr,rt<<1|1));
return ret;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>c>>s>>r;
build(1,c,1);
while(r--)
{
cin>>o>>d>>n;
update(o,d-1,n,1);
if(query(o,d-1,1)>s)
{
update(o,d-1,-n,1);
cout<<"N\n";
}
else
cout<<"T\n";
}
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...