#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3e5 + 5;
int r[N * 4], tc[N * 4], u[N * 4];
void push (int v, int tl, int tr) {
if (u[v]) {
int tm = (tl + tr) / 2;
u[v * 2] = max(u[v], u[v * 2]), u[v * 2 + 1] = max(u[v] + (tm - tl + 1), u[v * 2 + 1]);
u[v] = 0;
}
}
void upd (int v, int tl, int tr, int l, int r, int val) {
if (tl >= l && tr <= r) {
u[v] = max(u[v], val + tl - l);
return;
} if (tl > r || tr < l) return;
int tm = (tl + tr) / 2;
push(v, tl, tr);
upd(v * 2, tl, tm, l, r, val);
upd(v * 2 + 1, tm + 1, tr, l, r, val);
}
void out (int v, int tl, int tr) {
if (tl == tr) {
cout << u[v] << ' ';
return;
} int tm = (tl + tr) / 2;
push(v, tl, tr);
out(v * 2, tl, tm);
out(v * 2 + 1, tm + 1, tr);
}
int main () {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t = 1; //cin >> t;
while (t--) {
int n; cin >> n;
for (int i = 0; i < N * 4; i++) r[i] = 0, u[i] = 0;
int q; cin >> q;
while (q--) {
int l, r, x; cin >> l >> r >> x;
upd(1, 1, n, l, r, x);
} out(1, 1, n);
} return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
4 ms |
9668 KB |
Output is correct |
3 |
Correct |
4 ms |
9684 KB |
Output is correct |
4 |
Correct |
4 ms |
9684 KB |
Output is correct |
5 |
Correct |
5 ms |
9684 KB |
Output is correct |
6 |
Correct |
6 ms |
9684 KB |
Output is correct |
7 |
Correct |
112 ms |
13388 KB |
Output is correct |
8 |
Correct |
119 ms |
13916 KB |
Output is correct |
9 |
Correct |
119 ms |
14092 KB |
Output is correct |
10 |
Correct |
133 ms |
14096 KB |
Output is correct |
11 |
Correct |
142 ms |
14812 KB |
Output is correct |
12 |
Correct |
143 ms |
14932 KB |
Output is correct |
13 |
Correct |
151 ms |
15196 KB |
Output is correct |
14 |
Correct |
158 ms |
15076 KB |
Output is correct |
15 |
Correct |
171 ms |
15828 KB |
Output is correct |
16 |
Correct |
180 ms |
15872 KB |
Output is correct |
17 |
Correct |
173 ms |
15972 KB |
Output is correct |
18 |
Correct |
209 ms |
16448 KB |
Output is correct |
19 |
Correct |
188 ms |
16084 KB |
Output is correct |
20 |
Correct |
214 ms |
17356 KB |
Output is correct |