Cod sursa(job #1337263)

Utilizator bogdanpaunFMI Paun Bogdan Gabriel bogdanpaun Data 8 februarie 2015 19:57:13
Problema Datorii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <fstream>

using namespace std;

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

int n , m , i , x  , y , z;
int a[15005];

void update(int pos,int val){
    for(; pos<=n; pos+=pos&-pos) a[pos]+=val;
}
int query(int pos){
    int sol = 0;
    for(;pos; pos-=pos&-pos) sol += a[pos];
    return sol;
}

int main()
{
    f >> n >> m;
    for(i=1;i<=n;++i){
        f >> x;
        update( i , x);
    }
    for(i=1;i<=n;++i){
        f >> x >> y >> z;
        if( x ){
            g << ( query(z) - query(y-1) ) << '\n';
        }else{
            update( y , -z );
        }
    }

    return 0;
}