思路没什么好说的
直接上模版
P3374:
#include<bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
int n, m;
int a[N];
int s[N];
int LLLOOOWWWBBBIIITTT (int x) {
return x & (-x);
}
void Jia (int x, int y) {
for (; x <= n; x += LLLOOOWWWBBBIIITTT (x)) s[x] += y;
}
int HE (int x) {
int ans = 0;
for (; x; x -= LLLOOOWWWBBBIIITTT (x)) ans += s[x];
return ans;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i], Jia (i, a[i]);
while (m--) {
int x, y, z;
cin >> x >> y >> z;
if (x == 1) Jia (y, z);
else cout << HE (z) - HE (y - 1) << endl;
}
return 0;
}
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 5e5 + 10;
LL n, m;
LL a[N];
LL s[N];
LL LLLOOOWWWBBBIIITTT (LL x) {
return x & (-x);
}
void Jia (LL x, LL y, LL z) {
for (; x <= y; x += LLLOOOWWWBBBIIITTT (x)) s[x] += z;
}
LL HE (LL x) {
LL ans = 0;
for (; x; x -= LLLOOOWWWBBBIIITTT (x)) ans += s[x];
return ans;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (LL i = 1; i <= n; i++) cin >> a[i], s[i] = a[i];
while (m--) {
LL x;
cin >> x;
if (x == 1) {
LL y, z, asdf;
cin >> y >> z >> asdf;
Jia (y, n, asdf);
Jia (z + 1, n, -asdf);
}
else {
LL y;
cin >> y;
cout << HE (y) << endl;
}
}
return 0;
}