1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| #include <cstdio>
using namespace std; using LL = long long; const int N = 1000001; int n, q, x, y, z; LL c[N];
int lowbit(int x) { return x & -x; }
void add(int i, int k) { for (; i <= n; i += lowbit(i)) c[i] += k; }
LL getSum(int i) { LL s = 0; for (; i > 0; i -= lowbit(i)) s += c[i]; return s; }
int main() { scanf("%d%d", &n, &q); for (int i = 1; i <= n; ++i) { scanf("%d", &x); c[i] += x; int j = i + lowbit(i); if (j <= n) c[j] += c[i]; } for (int i = 0; i < q; ++i) { scanf("%d%d%d", &x, &y, &z); if (x == 1) add(y, z); else printf("%lld\n", getSum(z) - getSum(y - 1)); } return 0; }
|