二维树状数组模板
#include<cstdio>
#include<cstdlib>
#include<cstring>
int num[10001][10001]={0},tree[10001][10001]={0};
int n,x,y;
int lowbit(int x)
{
return x&(-x);
}
int sum(int x,int y)
{
int sum = 0;
for(int i=x;i>0;i-=lowbit(i))
for(int j=y;j>0;j-=lowbit(j))
sum += tree[i][j];
return sum;
}
void plus(int x,int y,int num)
{
for(int i=x;i<=n;i+=lowbit(i))
for(int j=y;j<=n;j+=lowbit(j))
tree[i][j] += num;
}
int main()
{
scanf("%d",&n);
scanf("%d %d",&x,&y);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
scanf("%d",&num[i][j]);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
plus(i,j,num[i][j]);
printf("%d\n",sum(x,y));
return 0;
}