Pagini recente » Cod sursa (job #2491658) | Cod sursa (job #1343972) | Cod sursa (job #1797489) | Cod sursa (job #2281629) | Cod sursa (job #1626193)
#include <cstdio>
#include <vector>
using namespace std;
vector<int> tree;
int n, M;
void update(int idx, int val)
{
while(idx<=n)
{
tree[idx]+=val;
idx+=(idx&-idx);
}
}
int read(int idx)
{
int sum=0;
while(idx>0)
{
sum+=tree[idx];
idx-=(idx&-idx);
}
return sum;
}
void initializare()
{
int i, x;
scanf("%d%d", &n, &M);
tree.assign(n+1,0);
for(i=1;i<=n;++i)
{
scanf("%d", &x);
update(i, x);
}
}
void rezolva_problema()
{
initializare();
int i;
for(i=0;i<M;++i)
{
int t, x, y;
scanf("%d%d%d", &t, &x, &y);
if(t==0)
update(x, -y);
else
printf("%d\n", read(y)-read(x-1));
}
}
int main()
{
freopen("datorii.in", "r", stdin);
freopen("datorii.out", "w", stdout);
rezolva_problema();
return 0;
}