- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDifference_Array_1D.cpp
More file actions
Latest commit
30 lines (25 loc) · 576 Bytes
/
Copy pathDifference_Array_1D.cpp
File metadata and controls
30 lines (25 loc) · 576 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
#include<bits/stdc++.h>
usingnamespacestd;
constint N = 1e6+7;
int32_tmain () {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int n, q; cin >> n >> q;
vector<int> v(n+1), d(n+2, 0), pred(n+2, 0);
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
int x, y, m;
while(q--) {
cin >> x >> y >> m;
d[x] += m;
d[y+1] -= m;
}
for (int i = 1; i <= n; i++) {
pred[i] = pred[i-1] + d[i];
v[i] += pred[i];
}
for (int i = 1; i <= n; i++) {
cout << v[i] << "";
}
cout << endl;
}