Cod sursa(job #2498397)

Utilizator 0738076326Simon Wil 0738076326 Data 23 noiembrie 2019 21:00:52
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("datorii.in");
ofstream g("datorii.out");

const int NMAX = 15005;
const int MMAX = 100005;
int n,m,aib[NMAX];

void add(int pos, int val){

    while(pos <= n){

        aib[pos] += val;
        pos += pos & -pos;

    }

}

int sum(int pos){
    int sum = 0;

    while(pos > 0){

        sum += aib[pos];
        pos -= pos & -pos;

    }

    return sum;

}

int main(){
    int i,j,x,type,y;

    f >> n >> m;

    for(i = 1 ; i <= n ; i++){

        f >> x;
        add(i, x);

    }

    while(m--){
        f >> type >> x >> y;
        if(type == 0)
            add(x, -y);
        else
            g << sum(y) - sum(x - 1) << "\n" ;
    }

    return 0;
}