Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int MAX = 300000;
- int n, q, BIT[MAX], arr[MAX];
- int query(int x) {
- int s = 0;
- while(x) s += BIT[x], x -= x&-x;
- return s;
- }
- void update(int x, int value) {
- while(x <= n) BIT[x] += value, x += x&-x;
- }
- int32_t main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cin >> n;
- for(int i = 1; i <= n; i++) {
- cin >> arr[i];
- update(i, arr[i]);
- }
- cin >> q;
- while(q--) {
- int o, a, b;
- cin >> o >> a >> b;
- if(o == 1) {
- cout << query(b) - query(a - 1) << endl;
- } else {
- update(a, -arr[a]);
- arr[a] = b;
- update(a, arr[a]);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement