树状数组70分RE
  • 板块学术版
  • 楼主Xiao_heihei
  • 当前回复3
  • 已保存回复3
  • 发布时间2023/1/7 11:06
  • 上次更新2023/10/24 05:19:05
查看原帖
树状数组70分RE
766111
Xiao_heihei楼主2023/1/7 11:06

原题
差值数组开到4倍依然RE,储存参部分已经用了long long
pSEIITs.png

谢谢各位dalao,如果蒟蒻眼瞎望轻喷

#include <bits/stdc++.h>
using namespace std;
int n,m;
long long a[50005],t[200020];
int lowbit(int k){
	return k&(-k);
}
void Add(int x,long long k){//x=s,k=u
	while(x<=n){
		t[x]+=k;
		x+=lowbit(x);
	}
}
long long Get(int x){
	long long ans=0;
	while(x>0){
		ans+=t[x];
		x-=lowbit(x);
	}
	return ans;
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		Add(i,a[i]-a[i-1]);
	}
	while(m--){
		int r,s,t;
		long long u;
		cin>>r;
		if(r==1){
			cin>>s>>t>>u;
			Add(t+1,-u);
			Add(s,u);
		}
		else{
			cin>>s;
			cout<<Get(s)<<endl;
		}
	}
	return 0;
}
2023/1/7 11:06
加载中...