xfstart07
Get busy living or get busy dying

#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 ;
}





posted on 2009-06-28 02:03 xfstart07 阅读(125) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理