Cod sursa(job #2452420)

Utilizator IoanaDraganescuIoana Draganescu IoanaDraganescu Data 30 august 2019 17:20:49
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int n, m, aib[15005];

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

int query(int poz){
    int s = 0;
    for (int i = poz; i > 0; 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(i, x);
    }
    while (m--){
        int k, a, b;
        fin >> k >> a >> b;
        if (!k)
            update(a, -b);
        else
            fout << query(b) - query(a - 1) << '\n';
    }
    return 0;
}