Pagini recente » Cod sursa (job #645649) | Cod sursa (job #2609246) | Cod sursa (job #2222905) | Cod sursa (job #318590) | Cod sursa (job #851980)
Cod sursa(job #851980)
#include<stdio.h>
#include<cmath>
#define Nmax 15010
int N,M,i,SqrtN,V[Nmax],B[1500];
int main() {
freopen("datorii.in","r",stdin);
freopen("datorii.out","w",stdout);
scanf("%d %d",&N,&M);
SqrtN = (int)sqrt(N) ;
//if( SqrtN != sqrt(N) ) SqrtN++ ;
for( i = 0 ; i < N ; i++ ) {
scanf("%d",&V[i] ) ;
B[ i / SqrtN ] += V[i] ;
}
for( i = 1 ; i <= M ; i++ ) {
int op,p1,p2;
scanf("%d %d %d",&op,&p1,&p2) ;
if( op ) {
p1-- ; p2-- ;
int b1 = p1/ SqrtN ;
int b2 = p2/ SqrtN ;
int sol = 0, j = 0 ;
if( b1 == b2 )
for( j = p1 ; j <= p2 ; j++ ) sol += V[j] ;
else {
for( j = p1 ; j < (b1+1) * SqrtN ; j++ ) sol += V[j] ;
for( j = b1+1 ; j < b2 ; j++ ) sol += B[j] ;
for( j = b2 * SqrtN ; j <= p2 ; j++ ) sol += V[j] ;
}
printf("%d\n",sol);
}
else
{
p1--;
int b = p1/SqrtN;
V[p1] -= p2 ;
B[b] -= p2 ;
}
}
return 0 ;
}