Cod sursa(job #1001103)
| Utilizator | Data | 24 septembrie 2013 15:20:13 | |
|---|---|---|---|
| Problema | Datorii | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.96 kb |
#include<stdio.h>
unsigned v[15005],s[15005],p2[15005];
int main()
{
freopen("datorii.in","r",stdin);
freopen("datorii.out","w",stdout);
unsigned n,m,i,j,x,k,a,b,sp,c;
scanf("%u%u",&n,&m);
for(i=1;i<=n;i++)
{
scanf("%u",&v[i]);
j=i & (-i);
k=0;
p2[i]=j;
while(j>0)
{
j=j/2;
k++;
}
for(j=i-k+1;j<=i;j++)
s[i]=s[i]+v[j];
}
for(i=1;i<=m;i++)
{
scanf("%u%u%u\n",&c,&a,&b);
if(c==0)
s[a]=s[a]-b;
else
{
j=b;
sp=0;
while(j>0)
{
sp=sp+s[j];
j=j-p2[j];
}
j=a-1;
while(j>0)
{
sp=sp-s[j];
j=j-p2[j];
}
printf("%u\n",sp);
}
}
return 0;
}
