Link to this code: https://cses.fi/paste/adb58755bf3a45a4ad3ab9/
#include "bits/stdc++.h"
using namespace std;
using LL = long long;

struct Segment {
	int n;
	vector<LL> t;

	Segment(int _n) {
		for (n = 1; n < _n; n *= 2)
			;
		t.resize(2 * n);
	}

	void update(int p, int x) {
		p += n;
		t[p] = x;
		while (p > 1) {
			t[p / 2] = t[p] + t[p ^ 1];
			p /= 2;
		}
	}

	LL _query(int i, int a, int b, int l, int r) {
		// i è responsabile di [a, b)
		// la query è su [l, r)
		if (b <= l || r <= a) return 0;
		if (l <= a && b <= r) return t[i];
		int m = (a + b) / 2;
		return _query(2*i, a, m, l, r) + _query(2*i+1, m, b, l, r);
	}

	LL query(int l, int r) {
		return _query(1, 0, n, l, r);
	}
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n; cin >> n;
	int q; cin >> q;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}

	Segment st(n);
	for (int i = 0; i < n; ++i) {
		st.update(i, a[i]);
	}

	for (int i = 0, t, a, b; i < q; ++i) {
		cin >> t >> a >> b;
		if (t == 1) {
			--a;
			st.update(a, b);
		} else {
			cout << st.query(a - 1, b) << "\n";
		}
	}
}