Cod sursa(job #3309583)

Utilizator Grama2008Grama Andrei Teodor Grama2008 Data 6 septembrie 2025 15:30:44
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <bits/stdc++.h>

using namespace std;

int bit[15005],n,m;

int query(int pos){
    int res=0;
    while (pos>0){
        res+=bit[pos];
        pos&=(pos-1);
    }
    return res;
}

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

int main()
{
    freopen("datorii.in", "r", stdin);
    freopen("datorii.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>m;
    for (int i=1;i<=n;i++){
        int a;cin>>a;
        update(i,a);
    }
    while (m--){
        int op,a,b;cin>>op>>a>>b;
        if (op==0){
            update(a,-b);
        }
        else if (op==1){
            cout<<query(b)-query(a-1)<<'\n';
        }
    }
    return 0;
}