mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 03:31:59 +00:00
798. 差分矩阵
https://www.acwing.com/problem/content/submission/code_detail/9152970/
This commit is contained in:
parent
14308b5cfd
commit
ce05e9d4dd
36
AcWing/798/798.cpp
Normal file
36
AcWing/798/798.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
int n, m, q, c, b[1005][1005];
|
||||
|
||||
int main() {
|
||||
cin >> n >> m >> q;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 1; j <= m; j++) {
|
||||
cin >> c;
|
||||
b[i][j] += c;
|
||||
b[i + 1][j] -= c;
|
||||
b[i][j + 1] -= c;
|
||||
b[i + 1][j + 1] += c;
|
||||
}
|
||||
}
|
||||
while (q--) {
|
||||
int x1, y1, x2, y2;
|
||||
cin >> x1 >> y1 >> x2 >> y2 >> c;
|
||||
b[x1][y1] += c;
|
||||
b[x2 + 1][y1] -= c;
|
||||
b[x1][y2 + 1] -= c;
|
||||
b[x2 + 1][y2 + 1] += c;
|
||||
}
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 1; j <= m; j++) {
|
||||
b[i][j] += b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1];
|
||||
cout << b[i][j] << ' ';
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user