Mai intai trebuie sa te autentifici.
Cod sursa(job #330385)
Utilizator | Data | 9 iulie 2009 20:21:30 | |
---|---|---|---|
Problema | Datorii | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 1.42 kb |
#include <stdio.h>
#define N 15050
int n,m;
int v[N],c[N],s[N],exp[15];
void exp_2()
{
int i;
exp[0]=1;
for (i=1; i<=14; i++)
exp[i]=exp[i-1]*2;
}
void read()
{
scanf("%d %d\n",&n,&m);
int i,nr,t,salv;
for (i=1; i<=n; i++)
{
scanf("%d",&v[i]);
s[i]=s[i-1]+v[i];
}
for (i=1; i<=n; i++)
{
nr=0;
salv=i;
while (salv%2==0)
{
nr++;
salv/=2;
}
t=i-exp[nr]+1;
c[i]=s[i]-s[t-1];
}
}
void solve()
{
int i,x,y,z,poz,s1,s2,salv;
for (i=1; i<=m; i++)
{
scanf("%d%d%d",&x,&y,&z);
if (x==0)
{
poz=0;
while (y<=n)
{
c[y]=c[y]-z;
salv=y;
while (salv % 2==0)
{
poz++;
salv/=2;
}
if (poz>12)
break;
y=y+exp[poz];
poz++;
}
}
if (x==1)
{
s1=0;
poz=0;
while (z>0)
{
s1=s1+c[z];
salv=z;
while (salv % 2==0)
{
poz++;
salv/=2;
}
if (poz>12)
break;
z=z-exp[poz];
poz++;
}
y--;
s2=0;
poz=0;
while (y>0)
{
s2=s2+c[y];
salv=y;
while (salv % 2==0)
{
poz++;
salv/=2;
}
if (poz>12)
break;
y=y-exp[poz];
poz++;
}
printf("%d\n",s1-s2);
}
/*for (j=1; j<=n; j++)
printf("%d ",c[j]);
printf("\n");*/
}
}
int main()
{
freopen("datorii.in","r",stdin);
freopen("datorii.out","w",stdout);
exp_2();
read();
solve();
return 0;
}