Cod sursa(job #1457421)

Utilizator theprdvtheprdv theprdv Data 3 iulie 2015 12:57:23
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <stdlib.h>
#define zeros(x) ((x ^ (x - 1)) & x)

using namespace std;

int N, M, BIT[15001];

void update(int p, int q){
	for (; p <= N; p += zeros(p))
		BIT[p] += q;
}

int query(int p){
	int ans = 0;
	for (; p; p -= zeros(p))
		ans += BIT[p];
	return ans;
}

int main(){
	freopen("datorii.in", "r", stdin);
	freopen("datorii.out", "w", stdout);

	scanf("%d %d", &N, &M);
	for (int i = 1, x; i <= N; ++i)
		scanf("%d", &x),
		update(i, x);

	for (int type, a, b; M; --M){
		scanf("%d %d %d", &type, &a, &b);
		if (!type) update(a, -b);
		else printf("%d\n", query(b) - query(a - 1));
	}

	return 0;
}