0pts
查看原帖
0pts
575655
Chtholly_is_cute楼主2024/10/3 10:47

code:

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll a[555555];
int n,m;
#define lowbit(x) (x&(-x))
void add(int x,ll y){
	while(x<=n){
		a[x]+=y;
		x+=lowbit(x);
	}
}
ll query(int x){
	ll ans=0;
	while(x){
		ans+=a[x];
		x-=lowbit(x);
	}
	return ans;
}

int main(){
	cin>>n>>m;
	int op,l,r;ll x;
	for(int i=1;i<=m;i++){
		cin>>op;
		if(op==1){
			cin>>l>>r>>x;
			add(l,x);
			add(r+1,-x);
		}
		else if(op==2){
			cin>>op;
			cout<<query(op)<<endl;
		}
	}
}

WA 100%

2024/10/3 10:47
加载中...