http://wenku.baidu.com/link?url=vyLnMDMwmb7-1hyKp_DwOLA_HEx_fFrd2PSxuvQs8Z2mjGbDcnkfAeamg8e_oR_dkTqy1CiNAqzXG_dAHQcgKAWKFtrD9wPp-Y6v5OYbQLa

#include<iostream>
#include<cstdio>
using namespace std;
int n,m;
int a[121][121]={},c[121][121]={};
inline int lowbit(int x){return x&(-x);}
void change(int x,int y,int h)
{
     int i,j;
     for (i=x;i<=n;i+=lowbit(i))
      for (j=y;j<=m;j+=lowbit(j))
      c[i][j]+=h;
}
int sum(int x,int y)
{
    int ans=0,i,j;
    for (i=x;i>0;i-=lowbit(i))
     for (j=y;j>0;j-=lowbit(j))
     ans+=c[i][j];
     
    return ans;
}
int main()
{
    int i,j;
    scanf("%d%d",&n,&m);
    for (i=1;i<=n;i++)
    {
        for (j=1;j<=m;j++)
        scanf("%d",&a[i][j]),change(i,j,a[i][j]);
    }
    
    for (i=1;i<=n;i++)
    {
        for (j=1;j<=m;j++)
        printf("%d  ",sum(i,j));
        printf("\n");
    }
    
    system("pause");
    return 0;
}