Cod sursa(job #3197952)

Utilizator AndPitAndreeaPiticar AndPit Data 27 ianuarie 2024 18:41:24
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <fstream>
using namespace std;
ifstream f("datorii.in");
ofstream g("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;
    rez=0;
    while(poz>=1){
        rez+=t[poz];
        poz&=(poz-1);
    }
    return rez;
}
int main(){
    int m;
    f>>n>>m;
    for(int i=1;i<=n;++i){
        int x;
        f>>x;
        update(i,x);
    }
    for(int i=1;i<=m;++i){
        int cer,x,y;
        f>>cer>>x>>y;
        if(cer)
            g<<query(y)-query(x-1)<<'\n';
        else update(x,-y);
    }
    return 0;
}