Cod sursa(job #35396)

Utilizator amadaeusLucian Boca amadaeus Data 22 martie 2007 00:28:51
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
// reimplementez BIT
#include <cstdio>

#define NX 15001

int A[ NX ];
int N, M;

void update( int x, int y ) {
	for( ; x <= N; x += x & ( x^(x-1) ) )
		A[x] += y;
}

int query( int x ) {
	int r = 0;
	for( ; x; x &= x-1 )
		r += A[x];
	return r;
}

void cit() {
	int i, op, x, y;
	scanf( "%d%d", &N, &M );

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

	for( ; M; M-- ) {
		scanf( "%d%d%d", &op, &x, &y );
		if( op == 0 )
			update( x, -y );
		else
			printf( "%d\n", query( y ) - query( x - 1 ) );
	}
}

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

	return 0;
}