Cod sursa(job #3341079)

Utilizator bogdan1479Luca Bogdan Alexandru bogdan1479 Data 17 februarie 2026 19:47:41
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 = 15001;

int n, m;

int aib[NMAX];

void add(int poz, int val) {
    while(poz <= n) {
        aib[poz] += val;
        poz += poz & (-poz);
    }
}

int sum(int poz) {
    int s = 0;
    while(poz) {
        s += aib[poz];
        poz &= poz - 1;
    }
    return s;
}

int main() {
    fin >> n >> m;

    for(int i = 1, x; i <= n; ++i) {
        fin >> x;
        add(i, x);
    }

    int t, a, b;

    while(m--) {
        fin >> t >> a >> b;

        if(t == 0) {
            add(a, -b);
        } else {
            fout << sum(b) - sum(a - 1) << '\n';
        }
    }
    return 0;
}