Pagini recente » Cod sursa (job #3142435) | Cod sursa (job #979692) | Cod sursa (job #326778) | Cod sursa (job #781928) | Cod sursa (job #1425393)
#include <cstdio>
using namespace std;
int n, m;
int a[15005], aib[15005];
inline int lsb(int x)
{
return x&-x;
}
void build(int pos, int val)
{
for(int i=pos; i<=n; i += lsb(i))
aib[i]+=val;
}
void update(int pos, int val)
{
for(int i=pos; i<=n; i += lsb(i))
aib[i]-=val;
}
int querry(int pos)
{
int s=0;
for(int i = pos; i > 0; i -= lsb(i))
s += aib[i];
return s;
}
int main()
{
freopen("datorii.in", "r", stdin);
freopen("datorii.out", "w", stdout);
scanf("%d%d", &n, &m);
for(int i=1; i<=n; i++)
{
int x;
scanf("%d", &x);
build(i, x);
}
for(int i=0; i<m; i++)
{
bool type;
int x, y;
scanf("%d%d%d", &type, &x, &y);
if(type==0)
{
update(x, y);
}
else
{
printf("%d\n", querry(y)-querry(x-1));
}
}
return 0;
}