AcWing796.子矩阵的和[操作系统入门]
AcWing 796. 子矩阵的和
#include <bits/stdc++.h>using namespace std;
const int N=1e3+10;
int a[N][N],S[N][N];
int main(){
int n,m,q;
scanf("%d%d%d",&n,&m,&q);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%d",&a[i][j]);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
S[i][j]=S[i-1][j]+S[i][j-1]-S[i-1][j-1]+a[i][j];
while(q--){
int x1,y1,x2,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
cout<<S[x2][y2]-S[x1-1][y2]-S[x2][y1-1]+S[x1-1][y1-1]<<endl;
}
return 0;
}
AcWing 796. 子矩阵的和
原文:https://www.cnblogs.com/wiseXu/p/13390424.html
以上是 AcWing796.子矩阵的和[操作系统入门] 的全部内容, 来源链接: utcz.com/z/518802.html