Cod sursa(job #1505380)

Utilizator tain1234andrei laur tain1234 Data 19 octombrie 2015 02:15:04
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <fstream>
using namespace std;//test AIB
int AIB[15001], N, M, a, b, c;
int q(int d){
	int sum = 0;
	for (; d>0; d -= d ^ (d - 1) & d) sum += AIB[d];
	return sum;
}
inline void update(int c, int Val){
	for (; c <= N; c += c ^ (c - 1) & c) AIB[c] += Val;
}
int main(){
	ofstream of("datorii.out");
	ifstream f("datorii.in");
	f >> N >> M; a = -1;
	for (int i = 1; i <= N; ++i)f >> b, update(i, b);
	for (int i = 0; i < M; ++i){
		f >> a >> b >> c;
		if (!a)update(b, -c);
		else of << q(c) - q(b - 1) << "\n";
	}
}