蒟蒻求调
查看原帖
蒟蒻求调
521890
上帝之鹰楼主2022/8/7 09:50
#include<iostream>
using namespace std;
#define int long long
int n,sum[100005],addv[100005],x,y;

void build(int o,int L,int R){
	addv[o]=0;
	if(L==R){
		sum[o]=0;
		return;
	}
	int M=(L+R)/2;
	build(o*2,L,M);
	build(o*2+1,M+1,R);
}
void update(int o,int L,int R){
	if(L==R){
		addv[o]+=y;
		return;
	}
	int M=(L+R)/2;
	if(x<=M){
		update(o*2,L,M);
	}else{
		update(o*2+1,M+1,R);
	}
	sum[o]=sum[o*2]+sum[o*2+1]+addv[o*2]+addv[o*2+1];
}
int query(int o,int L,int R){
	if(x<=L&&R<=y){
		return sum[o]+addv[o];
	}
	int M=(L+R)/2,ans=(min(R,y)-max(L,x)+1)*addv[o];
	if(x<=M) ans+=query(o*2,L,M);
	if(y>M) ans+=query(o*2+1,M+1,R);
	return ans;
}
signed main(){
	int w;
	cin>>n>>w;
	char op='a';
	for(int i=1;i<=w;++i){
		cin>>op;
		if(op=='x'){
			cin>>x>>y;
			update(1,1,n);
		}else if(op=='y'){
			cin>>x>>y;
			cout<<query(1,1,n)<<endl;
		}
	}
	return 0;
}

哪位大佬给我解释下为啥会RE?测试数据好好的,下了第一组数据,IDE上显示输入长度不合法

2022/8/7 09:50
加载中...