Cod sursa(job #12884)
Utilizator | Cristina Petrovici judy_k | Data | 5 februarie 2007 10:04:44 |
---|---|---|---|
Problema | Datorii | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 1.75 kb |
#include <stdio.h>
const int nmax=15010;
int n,m,i,j,k,a[nmax],b[nmax],c[nmax],d[nmax],e[nmax],x,y,z,s;
int main()
{
freopen("datorii.in","r",stdin);
freopen("datorii.out","w",stdout);
scanf("%d %d",&n,&m);
for (i=1;i<=n;++i)
scanf("%d ",&a[i]);
for (i=2;i<=n;++i)
a[i]+=a[i-1];
a[0]=0;
b[1]=a[n];
c[1]=1;
d[1]=1;
e[1]=n;
x=1;
y=n;
i=1;
j=1;
while (!(d[i]==1 && e[i]==1))
{
z=(d[i]+e[i])/2;
j++;
b[j]=a[z]-a[d[i]-1];
c[j]=i;
d[j]=d[i];
e[j]=z;
if (d[i]!=e[i])
{
b[j+1]=a[e[i]]-a[z];
c[j+1]=i;
d[j+1]=z+1;
e[j+1]=e[i];
j++;
}
i++;
}
k=j-n;
for (i=1;i<=m;++i)
{
scanf("%d %d %d",&x,&y,&z);
if (x==0)
{
j=k+y;
b[j]-=z;
while (j>1)
{
j=c[j];
b[j]-=z;
}
}
else
{
s=0;
for (j=1;j<=k+n;++j)
{
if (d[j]==y)
{
if (e[j]<=z)
{
s+=b[j];
if (e[j]==z) break;
else y=e[j]+1;
}
}
else
if (e[j]==z)
{
if (d[j]>=y)
{
s+=b[j];
if (d[j]==y) break;
else z=d[j]-1;
}
}
}
printf ("%d\n",s);
}
}
return 0;
}