怎么弄都0分,要疯了
查看原帖
怎么弄都0分,要疯了
672360
Ch35楼主2022/8/1 15:22

0分

#include<bits/stdc++.h>
using namespace std;
const int maxn=500000;
int a[maxn],tree[4*maxn],n,m,x,y,k;
short op;
void built(int o,int l,int r){
	if(l==r){
		tree[o]=a[l];
		return;
	}
	int m=(l+r)/2;
	built(o*2,l,m);
	built(o*2+1,m+1,r);
	tree[o]=tree[o*2]+tree[o*2+1];
}
void chaxun(int o,int l,int r){
	if(l==r){
		tree[o]+=y;
		return;
	}
	int m=(l+r)/2;
	if(x<=m)chaxun(o*2,l,m);
	else chaxun(o*2+1,m+1,r);
	tree[o]=tree[o*2]+tree[o*2+1];
}
int he(int o,int l,int r){
	if(l==r){
		return tree[o];
	}
	int m=(l+r)/2,ans=0;
	if(x<=m)ans+=he(o*2,l,m);
	if(y>m)ans+=he(o*2+1,m+1,r);
	return ans;
}
int main(){
	//freopen("tree.in","r",stdin);
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>a[i];
	built(1,1,n);
	for(int i=1;i<=m;i++){
		cin>>op;
		if(op==1){
			cin>>x>>k;
			chaxun(1,1,n);
		}
		if(op==2){
			cin>>x>>y;
			cout<<he(1,1,n)<<endl;
		}
	}
	return 0;
}
2022/8/1 15:22
加载中...