Cod sursa(job #3211756)

Utilizator slym20Badea Razvan Theodor slym20 Data 10 martie 2024 11:47:41
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <fstream>
using namespace std;

ifstream cin("datorii.in");
ofstream cout("datorii.out");

const int nmax = 15001;
int t[nmax], n;

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

int query(int poz){
    int rez = 0;
    while(poz >= 1){
        rez += t[poz];
        poz &= (poz - 1);
    }
    return rez;
}

int main(){
    int m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        int x;
        cin >> x;
        update(i, x);
    }

    for(int i = 1; i <= m; i++){
        int cer, x, y;
        cin >> cer >> x >> y;
        if(cer)
            cout << query(y) - query(x - 1) << '\n';
        else
            update(x, -y);
    }
    return 0;
}