Pagini recente » Cod sursa (job #2252476) | Statistici Ionescu Gabriel (Ionescu_Gabriel_323CB) | Cod sursa (job #1201425) | Cod sursa (job #1838285) | Cod sursa (job #3249848)
#include <bits/stdc++.h>
using namespace std;
int v[100001];
int n;
int query( int i ) {
int sum = 0;
while( i > 0 ) {
sum += v[i];
i -= i & -i;
}
return sum;
}
void update( int i, int val ) {
while ( i <= n ) {
v[i] += val;
i += i & -i;
}
}
int main()
{
ifstream fin( "datorii.in" );
ofstream fout( "datorii.out" );
int i, m, x, q, y;
fin >> n >> m;
for ( i = 1; i <= n; i++ ) {
fin >> x;
update( i, x );
}
for( i = 0; i < m; i++ ) {
fin >> q >> x >> y;
if ( q == 0 )
update(x,-y);
else
fout << query(y)-query(x-1) << '\n';
}
return 0;
}