#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <unordered_set>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <fstream>
#include <random>
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
const int N = 3e5 + 10;
int tree[4 * N];
int ans[N];
void update(int v, int tl, int tr, int l, int r, int val) {
if (tl > r || tr < l) return;
if (tl >= l && tr <= r) {
tree[v] = max(tree[v], val + tl - l);
return;
}
int tm = (tl + tr) / 2;
update(2 * v, tl, tm, l, r, val);
update(2 * v + 1, tm + 1, tr, l, r, val);
}
vector <int> cur;
void pushh(int v, int tl, int tr) {
bool ch = false;
if (tree[v]) {
cur.push_back(tree[v] - tl);
ch = true;
}
if (tl == tr) {
if (cur.empty()) ans[tl] = 0;
else ans[tl] = *max_element(cur.begin(), cur.end()) + tl;
}
else {
int tm = (tl + tr) / 2;
pushh(2 * v, tl, tm);
pushh(2 * v + 1, tm + 1, tr);
}
if (ch) cur.pop_back();
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int l, r, x;
cin >> l >> r >> x;
update(1, 1, n, l, r, x);
}
pushh(1, 1, n);
for (int i = 1; i <= n; i++) {
cout << ans[i] << " ";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
6 |
Correct |
3 ms |
344 KB |
Output is correct |
7 |
Correct |
131 ms |
5948 KB |
Output is correct |
8 |
Correct |
143 ms |
6996 KB |
Output is correct |
9 |
Correct |
154 ms |
6736 KB |
Output is correct |
10 |
Correct |
174 ms |
6252 KB |
Output is correct |
11 |
Correct |
166 ms |
8016 KB |
Output is correct |
12 |
Correct |
190 ms |
7508 KB |
Output is correct |
13 |
Correct |
232 ms |
8172 KB |
Output is correct |
14 |
Correct |
193 ms |
7676 KB |
Output is correct |
15 |
Correct |
219 ms |
8784 KB |
Output is correct |
16 |
Correct |
227 ms |
8676 KB |
Output is correct |
17 |
Correct |
255 ms |
9844 KB |
Output is correct |
18 |
Correct |
233 ms |
10832 KB |
Output is correct |
19 |
Correct |
274 ms |
10064 KB |
Output is correct |
20 |
Correct |
273 ms |
11752 KB |
Output is correct |