Cod sursa(job #2859754)

Utilizator LXGALXGA a LXGA Data 1 martie 2022 20:52:25
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.79 kb
#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;
}