mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-08 15:18:46 +00:00
796. 子矩阵的和
https://www.acwing.com/problem/content/submission/code_detail/9139040/
This commit is contained in:
parent
49f1d9c6fe
commit
39cfc3b8c0
27
AcWing/796/796.cpp
Normal file
27
AcWing/796/796.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user