Cod sursa(job #1148007)

Utilizator DanutsDanut Rusu Danuts Data 20 martie 2014 12:45:56
Problema Datorii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
#include<stdio.h>
#include<algorithm>
#include<math.h>
#define maxn 500010
using namespace std;
FILE *f=fopen("datorii.in","r");
FILE *g=fopen("datorii.out","w");
int v[maxn],n,m,x,y,cod;

void op0(int ind,int val){
    while(ind<=n){
        v[ind]+=val;
        ind +=(ind & -ind);
    }
}
int op1(int st,int dr){
    int s1=0,s2=0;
    st--;
    while(st>0){
        s1+=v[st];
        st-=(st & -st);
    }
    while(dr>0){
        s2+=v[dr];
        dr-=(dr & -dr);
    }
    return s2-s1;
}
int main (){
    fscanf(f,"%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        fscanf(f,"%d",&x);
        op0(i,x);
    }
    for(int i=1;i<=n;i++)
        fprintf(g,"%d ",v[i]);
    for(int i=1;i<=m;i++){
            fscanf(f,"%d%d%d",&cod,&x,&y);
            if(cod==0){
                op0(x,-y);
            }
            else
                fprintf(g,"%d\n",op1(x,y));
    }


    return 0;
}