Pagini recente » Cod sursa (job #136403) | Cod sursa (job #1130454) | Cod sursa (job #2990084) | Cod sursa (job #2607328) | Cod sursa (job #2611890)
#include <iostream>
#include <cstdio>
using namespace std;
const int N = 15 * 1e3;
const int dim = 1 << 17;
int barbati[N+5], f[N+1];
int AIB[N+1];
static inline int baieti ( int x ) {
return x & ( -x );
}
void update ( int poz, int q, int n ) {
for ( int i = poz; i <= n; i += baieti( i ) )
AIB[i] += q;
}
int q ( int poz ) {
int s = 0;
for ( int i = poz; i > 0; i -= baieti( i ) )
s += AIB[i];
return s;
}
char next_ch () {
static int bp = dim;
static char buff[dim];
if ( bp == dim ){
bp = 0;
fread ( buff, 1, dim, stdin );
}
return buff[bp++];
}
int get () {
int res = 0;
char ch;
while ( !isdigit ( ch = next_ch() ) );
do
res = res * 10 + ch - '0';
while ( isdigit ( ch = next_ch() ) );
return res;
}
int main()
{
freopen ( "datorii.in", "r", stdin );
freopen ( "datorii.out", "w", stdout );
ios::sync_with_stdio (false);
cin.tie (), cout.tie ();
int n, t, CASE;
n = get () ,t = get ();
for ( int i = 1; i <= n; i ++ )
barbati[i] = get (), f[i] = f[i-1] + barbati[i];
for ( int i = 1; i <= n; i ++ )
AIB[i] = f[i] - f[i-baieti(i)];
for ( int i = 1; i <= t; i ++ ) {
CASE = get ();
if ( CASE == 0 ) {
int x, poz;
poz = get (), x = get ();
update ( poz, -x, n );
}
else {
int st, dr;
st = get (), dr = get ();
cout << q ( dr ) - q ( st - 1 ) << '\n';
}
}
return 0;
}