Cod sursa(job #2286016)

Utilizator lupulescu2001Lupulescu Vlad lupulescu2001 Data 19 noiembrie 2018 18:27:44
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <fstream>

using namespace std;

ifstream fin("datorii.in");
ofstream fout("datorii.out");

const int nMax = 15000;
int n, m, aib[nMax + 5];

void Update(int val, int ind) {
    for (int i = ind; i <= n; i += i & (- i)) {
        aib[i] += val;
    }
}

int Query(int ind) {
    int s = 0;
    for (int i = ind; i >= 1; i -= i & (- i))
        s += aib[i];
    return s;
}

int main() {
    fin >> n >> m;
    for (int i = 1; i <= n; i++) {
        int x;
        fin >> x;
        Update(x, i);
    }
    for (int i = 1; i <= m; i++) {
        int op, x, y;
        fin >> op >> x >> y;
        if (op == 0)
            Update(-y, x);
        else
            fout << Query(y) - Query(x - 1) << '\n';
    }
}