Pagini recente » Monitorul de evaluare | Monitorul de evaluare | Monitorul de evaluare | Istoria paginii utilizator/mariaman | Cod sursa (job #999056)
Cod sursa(job #999056)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int BIT[15005];
int N, M, P, Q;
void update( int indice, int value )
{
int pozbit = 0;
while ( indice <= N ) {
BIT[indice] += value;
while ( ! ( indice & ( 1<<pozbit ) ) ) {
++pozbit;
}
indice += ( 1<<pozbit );
++pozbit;
}
}
int sum( int indice )
{
int sum = 0, pozbit = 0;
while ( indice > 0 ) {
sum += BIT[indice];
while ( !( indice & ( 1<<pozbit ) ) ) {
++pozbit;
}
indice -= ( 1<<pozbit );
++pozbit;
}
return sum;
}
int main()
{
int curent;
int i, bool;
freopen("datorii.in","r",stdin);
freopen("datorii.out","w",stdout);
scanf("%d",&N);
scanf("%d",&M);
for ( i=1; i<=N; i++ ) {
scanf("%d",&curent);
update(i, curent);
}
for ( ; M; M-- ) {
scanf("%d",&bool);
scanf("%d",&P);
scanf("%d",&Q);
if ( !bool ) {
update(P,-Q);
}
else {
printf("%d\n",sum(Q)-sum(P-1));
}
}
return 0;
}