#include<bits/stdc++.h>
#define int long long
using namespace std;
const int Max = 500005;
int a[Max];
int n,m;
int lowbit(int x) {
return x & -x;
}
void add(int x,int y) {
while(x <= n) {
a[x] += y;
x += lowbit(x);
}
}
int sum(int x) {
int ans = 0;
while(x > 0) {
ans += a[x];
x -= lowbit(x);
}
return ans;
}
signed main() {
cin>>n>>m;
int last = 0;
for(register int i = 1; i <= n; ++ i) {
int qwq;
cin>>qwq;
add(i,qwq - last);
last = qwq;
}
for(int i = 1; i <= m; ++ i) {
int qwq;
cin>>qwq;
if(qwq == 1) {
int x ,y,z ;
cin>>x>>y>>z;
add(x,z);
add(y + 1,-z);
} else {
int x ;
cin>>x;
cout << sum(x) << endl;
}
}
return 0;
}
标签:last,树状,int,cin,add,P3368,ans,模板,qwq
From: https://www.cnblogs.com/wenzhihao2023/p/17986673