//二维前缀和 #include <iostream> using namespace std; int n,m,q,tmp; int a[1010][1010]; int main() { cin>>n>>m>>q; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { scanf("%d",&tmp); a[i][j]=a[i][j-1]+a[i-1][j]-a[i-1][j-1]+tmp; } } int x1,y1,x2,y2; while (q--) { scanf("%d%d%d%d",&x1,&y1,&x2,&y2); printf("%d\n",a[x2][y2]-a[x2][y1-1]-a[x1-1][y2]+a[x1-1][y1-1]); } return 0; }
标签:std,前缀,int,矩阵,二维,1010 From: https://www.cnblogs.com/shinnyblue/p/17220460.html