Cod sursa(job #140969)

Utilizator butabuta radu gabriel buta Data 22 februarie 2008 15:51:51
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.1 kb
    #include<stdio.h>     
    long c[15010];     
   int main()     
    { freopen("datorii.in","r",stdin);     
     freopen("datorii.out","w",stdout);     
     long n,m,x,y,op,i,j,s1=0,s2=0;     
     scanf("%ld%ld",&n,&m);     
     for(i=1;i<=n;i++)     
        { scanf("%ld",&x);     
          j=i;     
          while(j<=n)     
        { c[j]+=x;     
          j+=(j^(j-1))&j;     
        }     
        }     
     for(i=1;i<=m;i++)     
        { scanf("%ld%ld%ld",&op,&x,&y);     
          if(op)     
          { s1=0;     
            while(y>0)     
              { s1+=c[y];     
            y-=(y^(y-1))&y;     
              }     
            s2=0;     
            x--;     
            while(x>0)     
           { s2+=c[x];     
             x-=(x^(x-1))&x;     
           }     
            printf("%ld\n",s1-s2);     
          }     
          else { j=x;     
             while(j<=n)     
           { c[j]-=y;     
             j+=(j^(j-1))&j;     
           }     
           }     
        }     
     printf("\n");     
     return 0;     
   }