Cod sursa(job #1025976)

Utilizator antonioteoZait Teodor Antonio antonioteo Data 10 noiembrie 2013 20:56:44
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <cstdio>
using namespace std;

#define NMAX 15001

int i, j, c, N, M;
int T, V, P, Q;

int AIB[NMAX];

void update(int poz, int val) {
	for (int x = poz; x <= N; x += (x & -x)) AIB[x] -= val;
}

int query(int i) {
	int result = 0;
	for (int x = i; x; x -= (x & -x)) result += AIB[x];
	return result;
}

int main() {
	freopen("datorii.in","r",stdin);
	freopen("datorii.out","w",stdout);
	scanf("%i%i", &N, &M);
	for (i = 1; i <= N; ++i) 
		scanf("%i", &AIB[i]);
	for (i = 1; i <= N; ++i) 
		AIB[i + (i & -i)] += AIB[i];
	for (i = 1; i <= M; ++i) {
		scanf("%i", &c);
		if (c == 0) {
			scanf("%i%i", &T, &V);
			update(T, V);
			continue;
		}
		scanf("%i%i", &P, &Q);
		printf("%i\n", query(Q) - query(P - 1));
	}
	return 0;
}