Cod sursa(job #3350000)

Utilizator Belea_DariusBelea Mihai Darius Belea_Darius Data 4 aprilie 2026 15:02:18
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <bits/stdc++.h>
#define MAXN 15000

using namespace std;

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

int aib[MAXN + 1], n;

int lsb(int x){
    return x & (-x);
}

void update(int pos, int val){
    while(pos <= n){
        aib[pos] += val;
        pos += lsb(pos);
    }
}
int preff(int pos){
    int rez = 0;

    while(pos){
        rez += aib[pos];
        pos -= lsb(pos);
    }
    return rez;
}
int query(int x, int y){
    return preff(y) - preff(x - 1);
}

int main()
{
    int m, i, t, x, y;

    fin >> n >> m;
    for(i = 1; i <= n; i++){
        fin >> x;
        update(i, x);
    }
    while(m--){
        fin >> t >> x >> y;

        if(t == 0){
            update(x, -y);
        }else{
            fout << query(x, y) << "\n";
        }
    }
    return 0;
}