Cod sursa(job #990874)

Utilizator BeilandArnoldArnold Beiland BeilandArnold Data 29 august 2013 09:30:47
Problema Datorii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <fstream>
short aib[15001];

int main(){
    std::ifstream fin("datorii.in");
    std::ofstream fout("datorii.out");

    unsigned  N,M;
    fin>>N>>M;

    unsigned temp1; int temp2; char c;

    for(unsigned i=1;i<=N;++i){
        fin>>temp2;
        temp1=i;
        while(temp1<=N){
            aib[temp1]+=temp2;
            temp1 += temp1&(-temp1);
        }
    }
    while(M--){
        fin>>c>>temp1>>temp2;
        if(c=='0'){
            while(temp1<=N){
                aib[temp1]-=temp2;
                temp1 += temp1&(-temp1);
            }
        }
        else{
            unsigned sum1=0,sum2=0;
            temp1--;
            while(temp1>0){
                sum1+=aib[temp1];
                temp1&=temp1-1;
            }
            while(temp2>0){
                sum2+=aib[temp2];
                temp2&=temp2-1;
            }
            fout<<sum2-sum1<<'\n';
        }
    }
}