Cod sursa(job #2672824)

Utilizator vansJos da pa perete vans Data 14 noiembrie 2020 23:19:49
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <bits/stdc++.h>

using namespace std;

const int NMAX = 15000;

int n, m, x, y, bit[NMAX + 1];
bool op;

inline void updBIT(int POZ, const int VAL) {
    for(; POZ <= n; POZ += POZ & -POZ)
        bit[POZ] += VAL;
}

inline int queryBIT(int POZ) {
    int TORET = 0;
    for(; POZ; POZ -= POZ & -POZ)
        TORET += bit[POZ];
    return TORET;
}

int main()
{
    freopen("datorii.in", "r", stdin);
    freopen("datorii.out", "w", stdout);
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; ++i)
        scanf("%d", &x),
        updBIT(i, x);
    while(m--) {
        scanf("%d%d%d", &op, &x, &y);
        if(!op) updBIT(x, -y);
        else printf("%d\n", queryBIT(y) - queryBIT(x - 1));
    }
    return 0;
}