啊这,求助16分
查看原帖
啊这,求助16分
670826
NianFeng楼主2023/7/17 16:48

rt,蜜汁RE,倒是对了 #2 and #8

代码如下

#include <bits/stdc++.h>
using namespace std;
const int N=60005;
int c,s,r,o,d,n;
struct TREE{
	int l,r,maxn;
	int lz;
}tree[N*4];
void build(int root,int l,int r){
	tree[root].l=l,tree[root].r=r;
	if(tree[root].l==tree[root].r){
		tree[root].maxn=tree[root].lz=0;
		return;
	}
	int mid=l+r>>1;
	int leftroot=root<<1;
	int rightroot=root<1|1;
	build(leftroot,l,mid);
	build(rightroot,mid+1,r);
	tree[root].maxn=tree[root].lz=0;
	return;
}
void lazy(int root,int k){
	tree[root].maxn+=k;
	tree[root].lz+=k;
	return;
}
void pushdown(int root){
	lazy(root<<1,tree[root].lz);
	lazy(root<<1|1,tree[root].lz);
	tree[root].lz=0;
	return;
}
void update(int root,int l,int r,int k){
	if(l<=tree[root].l&&tree[root].r<=r){
		lazy(root,k);
		return;
	}
	if(tree[root].lz) 
		pushdown(root);
	int mid=tree[root].l+tree[root].r>>1;
	int leftroot=root<<1;
	int rightroot=root<<1|1;
	if(l<=mid) update(leftroot,l,r,k);
	if(mid<r) update(rightroot,l,r,k);
	tree[root].maxn=max(tree[leftroot].maxn,tree[rightroot].maxn);
	return;
}
int query(int root,int l,int r){
	if(l<=tree[root].l&&tree[root].r<=r){
		return tree[root].maxn;
	}
	if(tree[root].lz)
		pushdown(root);
	int mid=tree[root].l+tree[root].r>>1;
	int leftroot=root<<1;
	int rightroot=root<<1|1;
	int ans=0;
	if(l<=mid) ans=max(ans,query(leftroot,l,r));
	if(mid<r) ans=max(ans,query(rightroot,l,r));
	return ans;
}
int main(){
	cin>>c>>s>>r;
	build(1,1,c); 
	for(int i=1;i<=r;i++){
		cin>>o>>d>>n;
		if(query(1,o,d-1)+n>s)
			cout<<"N\n";
		else{
			cout<<"T\n";
			update(1,o,d-1,n);
		}
	}
	return 0;
}

最无语的一点在于,我试着把tree数组后面的*4改大,然后……如你所见,改为*88都没用

2023/7/17 16:48
加载中...