Cod sursa(job #775810)

Utilizator ionut_blesneagIonut Blesneag ionut_blesneag Data 9 august 2012 00:30:44
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
/* Datorii */

#include<stdio.h>

using namespace std;

int n,m;
int i,j,k,c;
int arb[100001];

void update(int poz, int val)
{int C=0;
while(poz<=n)
  {arb[poz]+=val;
   while(!(poz & (1<<C)))   C++;
   poz+=(1<<C);
   C+=1;
   }
}

int sumr(int poz)
{int C=0, S=0;
 while(poz>0)
   {S+=arb[poz];
    while(!(poz & (1<<C))) C++;
     poz-=(1<<C);
     C+=1;
    }
 return S;   
}


int main()
{int x,y,z;

freopen("datorii.in","r",stdin);
freopen("datorii.out","w",stdout);

scanf("%d %d",&n,&m);
for(i=1; i<=n; i++)
  {scanf("%d",&c);
   update(i,c);}
for(i=1; i<=m; i++)
  {scanf("%d",&k);
   if(k==0)
    {scanf("%d %d",&x,&y);
     y=(-1)*y;
     update(x,y);}
   if(k==1)
    {scanf("%d %d",&x,&y);
     z=sumr(y)-sumr(x-1);
     printf("%d\n",z);}
  }
  
return 0;
}