Pagini recente » Monitorul de evaluare | Cod sursa (job #2969396) | Rating Petrescu Dan (dan89_eu) | Profil LucaYaya | Cod sursa (job #2186843)
#include <fstream>
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
const int nmax= 15000;
int n, m;
int aib[nmax+1];
void aib_update( int p, int x ) {
for ( int i= p; i<=n; i= i*2-(i&(i-1)) ) {
aib[i]+= x;
}
}
int aib_query( int p ) {
int sol= 0;
for ( int i= p; i>=1; i= (i&(i-1)) ) {
sol+= aib[i];
}
return sol;
}
int main( ) {
fin>>n>>m;
for ( int i= 1, x; i<=n; ++i ) {
fin>>x;
aib_update(i, x);
}
for ( int x, y, z; m>0; --m ) {
fin>>x>>y>>z;
if ( x==0 ) {
aib_update(y, -z);
} else {
fout<<aib_query(z)-aib_query(y-1)<<"\n";
}
}
return 0;
}