AcWing 796. 子矩阵的和
原题链接
简单
作者:
墨白
,
2021-02-16 21:27:29
,
所有人可见
,
阅读 291
题目描述
C++ 代码
#include <iostream>
using namespace std;
const int N = 1010;
int q[N][N];
int S[N][N];
int n , m , k;
int main(){
cin >> n >> m >> k;
for(int i = 1;i <= n;++i){
for(int j = 1;j <= m;++j){
cin >> q[i][j];
S[i][j] = S[i - 1] [j] + S[i][j - 1] - S[i - 1][j - 1] + q[i][j];
}
}
while(k--){
int x1,y1,x2,y2;
cin >> x1 >> y1 >> x2 >> y2;
cout << S[x2][y2] - S[x1 - 1][y2] - S[x2][y1 - 1] + S[x1 - 1][y1 - 1] << endl;
}
return 0;
}