Pagini recente » Cod sursa (job #405834) | Cod sursa (job #805602) | Cod sursa (job #367342) | Cod sursa (job #2543105) | Cod sursa (job #2252300)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
int n, m, t, v, p, q, fenwick[30000];
bool o;
int lsb(int pos)
{
return pos & -pos;
}
void Update(int pos, int val)
{
while(pos <= n)
{
fenwick[pos] += val;
pos += lsb(pos);
}
}
int Query(int pos)
{
int sum = 0;
while(pos > 0)
{
sum += fenwick[pos];
pos -= lsb(pos);
}
return sum;
}
int main()
{
fin >> n >> m;
for(int i = 1; i <= m; i++)
{
int x;
fin >> x;
Update(i, x);
}
for(int i = 1; i <= m; i++)
{
fin >> o;
if(o == 0)
{
fin >> t >> v;
Update(t, -v);
}
else
{
fin >> p >> q;
fout << Query(q) - Query(p-1) << '\n';
}
}
}