Pagini recente » Cod sursa (job #76315) | Cod sursa (job #2843286) | Cod sursa (job #1808083) | Cod sursa (job #2627667) | Cod sursa (job #287521)
Cod sursa(job #287521)
#include<stdio.h>
long n,m;
long v[20010];
long aib[20010];
long query(long x)
{
long s=0;
int i=0;
while(x>0)
{
s=s+aib[x];
for(;i<=31;i++)
if(x&(1<<i))
{
x=x-(1<<i);
break;
}
}
return s;
}
void update(long x,long s)
{
int i=0;
while(x<=n)
{
aib[x]-=s;
for(;i<=31;i++)
if(x&(1<<i))
{
x=x+(1<<i);
break;
}
}
}
void update_init(long x, long s)
{
int i=0;
while(x<=n)
{
aib[x]+=s;
for(;i<=31;i++)
if(x&(1<<i))
{
x=x+(1<<i);
break;
}
}
}
void read()
{
freopen("datorii.in","r",stdin);
freopen("datorii.out","w",stdout);
scanf("%ld%ld",&n,&m);
long i;
int tip;
long a,b;
for(i=1;i<=n;i++)
{
scanf("%ld",&v[i]);
update_init(i,v[i]);
}
for(i=1;i<=m;i++)
{
scanf("%d",&tip);
scanf("%ld%ld",&a,&b);
if(tip==0)
{
update(a,b);//ind a cu suma b
}
else
{
printf("%ld\n",query(b)-query(a-1));
}
}
}
int main()
{
read();
return 0;
}