Pagini recente » Cod sursa (job #1585497) | Cod sursa (job #1554245) | Cod sursa (job #2685651) | Cod sursa (job #2368507) | Cod sursa (job #499700)
Cod sursa(job #499700)
# include <cstdio>
# define verf ++poz == hg ? fread ( ch, 1, hg, stdin ), poz = 0 : 0
const char *FIN = "datorii.in", *FOU = "datorii.out" ;
const int MAX = 15005, hg = 1 << 13 ;
int Sum[MAX] ;
int N, M, poz ;
char ch[hg] ;
inline void cit ( int &x ) {
if ( ch[0] == '\0' ) fread ( ch, 1, hg, stdin ) ;
else for ( ; ch[poz] < '0' || ch[poz] > '9' ; verf ) ;
for ( x = 0 ; ch[poz] >= '0' && ch[poz] <= '9' ; x = x * 10 + ch[poz] - '0', verf ) ;
}
int main ( void ) {
freopen ( FIN, "r", stdin ) ;
freopen ( FOU, "w", stdout ) ;
cit ( N ) , cit ( M ) ;
for ( int i = 1, a, b; i <= N; ++i ) {
cit ( a ) ;
for ( b = i; b <= N; Sum[b] += a, b += b & -b ) ;
}
for ( int a, b, tip ; M ; --M ) {
cit ( tip ) , cit ( a ) , cit ( b ) ;
if ( tip ) {
int sol = 0 ;
for ( ; b > 0 ; sol += Sum[b], b -= b & -b ) ;
for ( --a ; a > 0 ; sol -= Sum[a], a -= a & -a ) ;
printf ( "%d\n", sol ) ;
} else {
for ( ; a <= N; Sum[a] -= b, a += a & -a ) ;
}
}
}