0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-24 04:48:52 +00:00
OI-codes/AcWing/796/796.cpp

28 lines
653 B
C++
Raw Normal View History

#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
int n, m, q, g[1005][1005], sum[1005][1005];
int main() {
cin >> n >> m >> q;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> g[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + g[i][j];
}
}
while (q--) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
cout << sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1] << endl;
}
return 0;
}