#include <stdio.h>
#define ll long long

int n, q, i, l, r, sz, high, pos, type;

ll val, res;
ll tree[1<<20];

int main() {
    scanf("%d %d", &n, &q);
    high = 32 - __builtin_clz(n>1 ? n-1 : 1);
    sz = 1 << high;

    for (i=0; i<n; i++) {
        scanf("%lld", &tree[i+sz]);
    }

    for (i=sz-1; i>0; i--) {
        tree[i] = tree[i<<1] + tree[i<<1|1];
    }

    while (q--) {
        scanf("%d", &type);

        if (type == 1) {
            // point update
            scanf("%d %lld", &pos, &val);
            pos += sz-1;
            tree[pos] = val;
            while (pos >>= 1) {
                tree[pos] = tree[pos<<1] + tree[pos<<1|1];
            }
        }
        else if (type == 2) {
            scanf("%d %d", &l, &r);
            res = 0LL;
            l += sz-1;
            r += sz;
            while (l<r) {
                if (l&1) {
                    res += tree[l++];
                }
                if (r&1) {
                    res += tree[--r];
                }
                l >>= 1;
                r >>= 1;
            }

            printf("%lld\n", res);
        }
        
    }

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: