Pagini recente » Cod sursa (job #1523067) | Cod sursa (job #1521158) | Cod sursa (job #2967672) | Cod sursa (job #2048653) | Cod sursa (job #1747930)
# include <iostream>
# include <fstream>
using namespace std;
# define MAX_N 15000
int aib[1 + MAX_N];
void update( int pos, int val ) {
if ( pos > 0 ) {
aib[pos] += val;
update( pos - ( pos & -pos ), val );
}
}
int query( int pos ) {
if ( pos > MAX_N )
return 0;
else
return aib[pos] + query( pos + ( pos & -pos ) );
}
int main() {
ifstream fin( "datorii.in" );
ofstream fout( "datorii.out" );
int n, m, i, c, a, b;
fin >> n >> m;
for ( i = 1; i <= n; i ++ ) {
fin >> a;
update( i, a );
}
for ( i = 0; i < m; i ++ ) {
fin >> c >> a >> b;
if ( c == 0 )
update( a, -b );
else
fout << query( a ) - query( b + 1 ) << '\n';
}
fin.close();
fout.close();
return 0;
}