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 43 44 45 46 47
| #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", &y); c[i] += y - x; int j = i + lowbit(i); if (j <= n) c[j] += c[i]; x = y; } for (int i = 0; i < q; ++i) { scanf("%d", &x); if (x == 1) { scanf("%d%d%d", &x, &y, &z); add(x, z); add(y + 1, -z); } else { scanf("%d", &x); printf("%lld\n", getSum(x)); } } return 0; }
|