Cod sursa(job #2314681)

Utilizator bleo16783FMI Bleotiu Cristian bleo16783 Data 8 ianuarie 2019 22:34:04
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <iostream>
#include <fstream>
using namespace std;
#define N 15155

inline int zeros (int x){
    return x & (-x);
}

int aib[N],i,n,m,task,x,y,ans;

void update (int poz, int x){
    for (int i = poz; i < n; i += zeros(i))
        aib[i] += x;
}

int compute (int poz) {
    int ans = 0;
    for (int i = poz; i > 0; i -= zeros(i))
        ans += aib[i];
    return ans;
}
int main()
{
    ifstream fin("datorii.in");
    ofstream fout("datorii.out");
    fin >> n >> m;
    ++n;
    for (i = 1; i < n; ++i){
        fin >> x;
        update (i, x);
    }
    for (i = 0; i < m; ++i){
        fin >> task >> x >> y;
        if (!task){
            update (x, -y);
        }
        else{
            ans = compute (y) - compute (x - 1);
            fout << ans << '\n';
        }
    }
    fin.close();
    fout.close();
    return 0;
}