Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int maxn = 1e5 + 5;
- int a[maxn], c[maxn], n;
- inline int lowbit(int x) { return x & -x; }
- void build()
- {
- for (int i = 1; i <= n; ++i)
- {
- c[i] += a[i];
- int j = i + lowbit(i);
- if (j <= n)
- c[j] += c[i];
- }
- }
- void add(int x, int k)
- {
- while (x <= n)
- c[x] = c[x] + k, x = x + lowbit(x);
- }
- int getsum(int x)
- {
- int ans = 0;
- while (x > 0)
- ans = ans + c[x], x = x - lowbit(x);
- return ans;
- }
- int main()
- {
- ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
- cin >> n;
- for (int i = 1; i <= n; i++)
- cin >> a[i];
- build();
- for (int i = 1; i <= 2 * n; i++)
- {
- int od, x, y;
- cin >> od >> x >> y;
- if (od == 1)
- add(x, y - a[x]), a[x] = y;
- else
- cout << (getsum(y) - getsum(x - 1)) << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment