Pagini recente » Cod sursa (job #807221) | Cod sursa (job #3295810)
#include <bits/stdc++.h>
using namespace std;
ifstream in("datorii.in");
ofstream out("datorii.out");
const int NMAX = 15000;
int n, m;
int aib[NMAX + 5];
void update(int pos, int x)
{
for(; pos <= n; pos += pos & (-pos))
{
aib[pos] += x;
}
}
int querry(int pos)
{
int ans = 0;
for(; pos > 0; pos -= pos & (-pos))
{
ans += aib[pos];
}
return ans;
}
int main()
{
in >> n >> m;
for(int i = 1; i <= n; ++i)
{
int x;
in >> x;
update(i, x);
}
for(int i = 1; i <= m; ++i)
{
int c, x, y;
in >> c >> x >> y;
if(c)
{
int q1 = querry(y);
int q2 = querry(x - 1);
out << q1 - q2 << '\n';
}
else
{
update(x, -y);
}
}
return 0;
}