Cod sursa(job #1606019)

Utilizator TeodorCotetCotet Teodor TeodorCotet Data 19 februarie 2016 18:44:47
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("datorii.in");
ofstream fout("datorii.out");


const int NMAX = 15000;
const int MMAX = 100000;

typedef long long in64;

int n; int m;

in64 aib[NMAX + 1];

int nextBit(int x) {

	return x & (-x);
}

void update(int pos, in64 val) {

	while(pos <= n) {
		
		aib[pos] += val;
		pos += nextBit(pos);
	}
}

in64 query(int pos) {

	in64 sum = 0;

	while(pos) {

		sum += aib[pos];
		pos -= nextBit(pos);
	}

	return sum;
}

int main() {

	fin >> n >> m;

	for(int i = 1; i <= n; ++i) {

		int val; fin >> val;
		update(i, val);
	}


	while(m--) {

		int type; int x; int y;

		fin >> type >> x >> y;

		if(type == 0) update(x, -y);

		if(type == 1) fout << query(y) - query(x - 1) << '\n';
	}

	return 0;
}