pku1195 Mobile phones

pku1195 Mobile phones

#include < iostream >
using   namespace  std;

int  N;
int  s[ 1100 ][ 1100 ];
int  lowbit( int  x){
    
return  x ^ (x & (x - 1 ));
}
void  insert( int  x, int  y, int  val){
    
for ( int  i = x;i <= N;i += lowbit(i))
        
for ( int  j = y;j <= N;j += lowbit(j))
            s[i][j]
+= val;
}
int  updata( int  x, int  y)
{
    
int  tmp = 0 ;
    
for ( int  i = x;i;i -= lowbit(i))
        
for ( int  j = y;j;j -= lowbit(j))
            tmp
+= s[i][j];
    
return  tmp;
}
int  main()
{
    
int  k;
    
while ( 1 ){
        scanf(
" %d " , & k);
        
if (k == 0 ){
            scanf(
" %d " , & N); N ++ ;
            memset(s,
0 , sizeof (s));
        }
        
else   if (k == 1 ){
            
int  x,y,val;
            scanf(
" %d%d%d " , & x, & y, & val);
            insert(x
+ 1 ,y + 1 ,val);
        }
        
else   if (k == 2 ){
            
int  x1,y1,x2,y2;
            scanf(
" %d%d%d%d " , & x1, & y1, & x2, & y2);
            
int  ans = updata(x2 + 1 ,y2 + 1 ) - updata(x1,y2 + 1 ) -
                       updata(x2
+ 1 ,y1) + updata(x1,y1);
            printf(
" %d\n " ,ans);
        }
        
else   break ;
    }
    
return   0 ;
}





你可能感兴趣的:(pku1195 Mobile phones)