Cod sursa(job #3040111)

Utilizator amcbnCiobanu Andrei Mihai amcbn Data 29 martie 2023 12:34:30
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
/// [A][M][C][B][N] ///
#include <bits/stdc++.h>
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");

const int nmax = 15e3;
int n, m;
int v[nmax + 1]{ 0 };
int t[nmax + 1]{ 0 };

void update(int i, int x) {
	for (; i <= n; i += i & -i) {
		t[i] += x;
	}
}

int query(int i) {
	int s = 0;
	for (; i > 0; i -= i & -i) {
		s += t[i];
	}
	return s;
}

int query(int i, int j) {
	return query(j) - query(i - 1);
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	fin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		fin >> v[i];
		update(i, v[i]);
	}
	while (m--) {
		int c, p, q;
		fin >> c >> p >> q;
		if (c) {
			fout << query(p, q) << '\n';
		}
		else {
			update(p, -q);
		}
	}
}