https://www.luogu.com.cn/problem/P3368
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define lowbit(x) x&(-x)
using ll = long long;
using pii = pair<int, int>;
const double PI = acos(-1);
const int N = 5e5 + 10;
const int mod = 1e9 + 7;
ll c[N],a[N];
int n,m;
void updata(int x,int k){
for(int i=x;i<=n;i+=lowbit(i))
c[i]+=k;
}
ll query(int x){
ll sum=0;
for(int i=x;i;i-=lowbit((i))){
sum+=c[i];
}
return sum;
}
void solve() {
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++)
{
int x=a[i]-a[i-1];
updata(i,x);
}
while(m--){
int ch;cin>>ch;
if(ch==1){
int x,y,k;cin>>x>>y>>k;
updata(x,k);
updata(y+1,-k);
}
else{
int x;cin>>x;
cout<<query(x)<<endl;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int T = 1;
//cin>>T;
while (T--) {
solve();
}
return 0;
}
标签:ch,const,树状,int,updata,ll,数组,using,单点
From: https://www.cnblogs.com/laileou/p/18667946