Pagini recente » Cod sursa (job #2882221) | Cod sursa (job #2630412) | Cod sursa (job #232078) | Cod sursa (job #1260385) | Cod sursa (job #2479050)
#include <bits/stdc++.h>
#define NM 15010
using namespace std;
ifstream fin ("datorii.in");
ofstream fout ("datorii.out");
void read();
int n, cod, Q;
int v[NM], t[NM];
int lg(int x)
{
return x&-x;
}
void update(int ind, int val)
{
while(ind<=n)
{
t[ind]-=val;
ind+=lg(ind);
}
}
int query(int x)
{
int s = 0;
while(x>=1)
{
s+=t[x];
x-=lg(x);
}
return s;
}
void upd_bld(int ind, int val)
{
while(ind<=n)
{
t[ind]+=val;
ind+=lg(ind);
}
}
void build()
{
for(int i=1; i<=n; i++)
upd_bld(i, v[i]);
}
int main()
{
read();
build();
while(Q--)
{
int x, y;
fin >> cod >> x >> y;
if(cod == 0)
update(x, y);
else fout << query(y) - query(x-1) << '\n';
}
return 0;
}
void read()
{
fin >> n >> Q;
for(int i=1; i<=n; i++)
fin >> v[i];
}