Pagini recente » Cod sursa (job #1130127) | Cod sursa (job #2616804) | Cod sursa (job #582587) | Cod sursa (job #2680247) | Cod sursa (job #2859754)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("datorii.in");
ofstream cout("datorii.out");
class ftree
{
int v[15001];
int sum(int pos)
{
int s = 0;
for (; pos > 0; pos -= (pos & (-pos)))
s += v[pos];
return s;
}
public:
int n;
void update(int pos, int val)
{
for (; pos <= n; pos += (pos & (-pos)))
v[pos] -= val;
}
int sum(int l, int r)
{
return sum(r) - sum(l - 1);
}
};
ftree aib;
int n, m, x;
int main()
{
ios_base::sync_with_stdio(false);
cin >> n >> m;
aib.n = n;
for (int i = 1; i <= n; i++)
{
cin >> x;
aib.update(i, -x);
}
int x, y, z;
for (int i = 1; i <= m; i++)
{
cin >> x >> y >> z;
if (x == 0)
aib.update(y, z);
else
cout << aib.sum(y, z) << '\n';
}
return 0;
}