Cod sursa(job #1651182)

Utilizator valentin50517Vozian Valentin valentin50517 Data 12 martie 2016 17:13:49
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <fstream>
 
#define zeros(x) (x & (-x))
 
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
 
int AIB[15100],X[15100],N,M,a,b;
bool u;

void add(int x,int pos){
    for(pos; pos<=N;pos+=zeros(pos) ){
        AIB[pos]+=x;
    }
}

void achitare(int x,int pos){
    for(pos; pos<=N;pos+=zeros(pos) ){
        AIB[pos]-=x;
    }
}

int query(int a){
    int sum = 0;
    for(;a > 0;a -= zeros(a)){
        sum+=AIB[a];
    }
    return sum;
}

int main(){
    fin >> N >> M;
    for(int i = 1,x;i<=N;i++){
        fin >> x;
		add(x,i);
    }
    for(int i = 0;i<M;i++){
        fin >> u >> a >> b;
        if(u) fout << query(b) - query(a-1) << '\n'; else achitare(b,a);
    }
    return 0;
}