Cod sursa(job #2847975)

Utilizator Langa_bLanga Radu Langa_b Data 11 februarie 2022 21:44:09
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <fstream>
using namespace std;
ifstream cin("datorii.in");
ofstream cout("datorii.out");
int n, m, cit[15002], aib[15002];
void build(int pos, int val) {
	while (pos <= n) {
		aib[pos] += val;
		pos += (pos & -pos);
	}
}
int query(int pos) {
	int ans = 0;
	while (pos > 0) {
		ans += aib[pos];
		pos -= (pos & -pos);
	}
	return ans;

}
int main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> cit[i];
		build(i, cit[i]);
	}
	int c, a, b;
	for (int i = 1; i <= m; i++) {
		cin >> c >> a >> b;
		if (c == 0) {
			build(a, -b);
		}
		else {
			int ans = query(b) - query(a - 1);
			cout << ans << '\n';
		}
	}
}