Pagini recente » Cod sursa (job #2923678) | Cod sursa (job #1480021) | Cod sursa (job #2441064) | Cod sursa (job #387970)
Cod sursa(job #387970)
/*
* File: main.cpp
* Author: virtualdemon
*
* Created on January 28, 2010, 8:55 PM
*/
#include <fstream>
#include <cstdlib>
/*
*
*/
using namespace std;
int N;
int *tree;
void Update1( int x, int y )
{
for( ; x <= N; x+=( x & - x ) )
tree[x]-=y;
}
void Update2( int x, int y )
{
for( ; x <= N; x+=( x & - x ) )
tree[x]+=y;
}
int Query( int y )
{int sum=0;
for( ; y > 0; y-=( y & -y ) )
sum+=tree[y];
return sum;
}
int main()
{int m, i, x, y, z;
ifstream in("datorii.in");
in>>N>>m;
tree=(int*)calloc( N+1, sizeof(int) );
for( i=1; i <= N; ++i )
{
in>>x;
Update2( i, x );
}
ofstream out("datorii.out");
for( i=0; i < m; ++i )
{
in>>x>>y>>z;
if( 0 == x )
Update1( y, z );
else out<<( Query(z)-Query(y-1) )<<'\n';
}
return 0;
}