0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 19:08:47 +00:00
Baoshuo Ren 2021-11-30 20:59:10 +08:00 committed by Baoshuo Ren
parent 49f1d9c6fe
commit 39cfc3b8c0
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

27
AcWing/796/796.cpp Normal file
View File

@ -0,0 +1,27 @@
#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;
}