题目描述
子矩阵的和 C++
样例
// 子矩阵的和
#include <iostream>
using namespace std;
const int N = 1010;
int arr[N][N];
int S[N][N];
int main()
{
int m, n, q;
cin >> m >> n >> q;
for (int i=1;i<=m;i++)
{
for (int j=1;j<=n;j++)
{
cin >> arr[i][j];
S[i][j] = S[i - 1][j] + S[i][j - 1] - S[i - 1][j - 1] + arr[i][j];
}
}
while (q-- > 0)
{
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
cout << S[x2][y2] - S[x2][y1 - 1] - S[x1 - 1][y2] + S[x1 - 1][y1 - 1] << endl;
}
return 0;
}