-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiff2dArrays.cpp
More file actions
32 lines (29 loc) · 765 Bytes
/
Copy pathDiff2dArrays.cpp
File metadata and controls
32 lines (29 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
using namespace std;
int const NMAX = 505;
int N, Q, l1, c1, l2, c2, x, a[NMAX][NMAX], b[NMAX][NMAX];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N;
for (int i = 1; i <= N; i++)
for (int j = 1; j <= N; j++)
cin >> a[i][j];
cin >> Q;
while (Q--) {
cin >> l1 >> c1 >> l2 >> c2 >> x;
b[l1][c1] += x;
b[l2 + 1][c1] -= x;
b[l1][c2 + 1] -= x;
b[l2 + 1][c2 + 1] += x;
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
b[i][j] += b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1];
a[i][j] += b[i][j];
cout << a[i][j] << ' ';
}
cout << '\n';
}
return 0;
}