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 48 49 50 51 52
| #include <bits/stdc++.h> #define MAX_N 100010 using namespace std; char ch_buffer; bool signum; inline void readInt(int &l) { l = 0; do ch_buffer = cin.get(); while ((ch_buffer < '0' || ch_buffer > '9') && ch_buffer != '0' && ch_buffer != '-'); if (ch_buffer == '-') ch_buffer = cin.get(), signum = true; while (ch_buffer <= '9' && ch_buffer >= '0') l = (l << 3) + (l << 1) + ch_buffer - '0', ch_buffer = cin.get(); if (signum) l = -l, signum = false; } int n, m; int a[MAX_N], tree[MAX_N << 2]; #define update(k) \ if (tree[k]) \ tree[k << 1] += tree[k], tree[k << 1 | 1] += tree[k], tree[k] = 0 void modify(int k, int s, int t, int l, int r, int x) { if (l <= s && t <= r) { tree[k] += x; return; } register int mid = s + t >> 1; update(k); if (l <= mid) modify(k << 1, s, mid, l, r, x); if (mid < r) modify(k << 1 | 1, mid + 1, t, l, r, x); } int query(int k, int s, int t, int p) { if (s == t) return tree[k] + a[s]; int mid = s + t >> 1; update(k); return p <= mid ? query(k << 1, s, mid, p) : query(k << 1 | 1, mid + 1, t, p); } int main() { ios::sync_with_stdio(false); cin.tie(NULL); readInt(n), readInt(m); for (register int i = 1; i <= n; i++) readInt(a[i]); for (register int j = 0, flag, l, r, x, i; j < m; j++) { readInt(flag); if (flag == 0) readInt(l), readInt(r), readInt(x), modify(1, 1, n, l, r, x); else readInt(i), cout << query(1, 1, n, i) << "\n"; } return 0; }
|