题解 | #【模板】二维前缀和#
【模板】二维前缀和
http://www.nowcoder.com/practice/99eb8040d116414ea3296467ce81cbbc
#include<stdio.h>
int main()
{
int n,m,x1,y1,x2,y2;
long long temp,q,arr[1001][1001]={0};
scanf("%d %d %lld",&n,&m,&q);
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j)
{
scanf("%lld",&temp);
arr[i][j] = temp+arr[i][j-1]+arr[i-1][j]-arr[i-1][j-1];
}
for(int i=0;i<q;++i)
{
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
printf("%lld\n",arr[x2][y2]-arr[x2][y1-1]-arr[x1-1][y2]+arr[x1-1][y1-1]);
}
return 0;
}