0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 21:36:36 +00:00
OI-codes/Luogu/P3374/P3374.cpp
2022-04-10 21:35:23 +08:00

47 lines
711 B
C++

#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 5e5 + 5;
int n, m, op, x, y;
int c[N];
inline int lowbit(int x) {
return x & -x;
}
void add(int x, int y) {
for (; x <= n; x += lowbit(x)) c[x] += y;
}
int sum(int x) {
int ans = 0;
for (; x; x -= lowbit(x)) ans += c[x];
return ans;
}
int main() {
std::ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1, x; i <= n; i++) {
cin >> x;
add(i, x);
}
while (m--) {
cin >> op >> x >> y;
if (op == 1) {
add(x, y);
} else { // op == 2
cout << sum(y) - sum(x - 1) << endl;
}
}
return 0;
}