#include <bits/stdc++.h>
#define f0(i, n) for(int i(0); i<(n); i++)
#define f1(i, n) for(int i(1); i<=(n); i++)
using namespace std;
typedef long long ll;
const int N = 300002;
int n, lazy[N*4], lo, hi, price;
int t[4*N];
void push(int k, int l, int r){
int x = lazy[k];
if(!x) return ;
t[k] = max(t[k], x);
lazy[k] = 0;
if(l != r){
int m = (l + r)/2;
/// l
lazy[k << 1] = max(lazy[k << 1], x);
/// m + 1
lazy[k << 1 | 1] = max(lazy[k << 1 | 1], x+ m - l + 1);
}
}
void up(int k, int l, int r){
push(k, l, r);
if(r < lo || l > hi) return ;
if(l >= lo && r <= hi){
lazy[k] = max(price + l - lo, lazy[k]);
push(k, l, r);
return ;
}
int m = (l + r)/2;
up(k << 1, l, m);
up(k << 1 | 1, m + 1, r);
t[k] = max(t[k << 1], t[k << 1 | 1]);
}
int get1(int k, int l, int r, int i){
push(k, l, r);
if(l==r) return t[k];
int m = (l + r)/2;
if(i >= l && i <= m) return get1(k << 1, l, m, i);
return get1(k << 1 | 1, m + 1, r, i);
}
int main(){
ios_base::sync_with_stdio(0);
int q; cin >> n >> q;
while(q--){
cin >> lo >> hi >> price;
up(1, 1, n);
}
f1(i, n) cout << get1(1, 1, n, i) << " ";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
420 KB |
Output is correct |
4 |
Correct |
3 ms |
440 KB |
Output is correct |
5 |
Correct |
4 ms |
596 KB |
Output is correct |
6 |
Correct |
5 ms |
704 KB |
Output is correct |
7 |
Correct |
189 ms |
7024 KB |
Output is correct |
8 |
Correct |
217 ms |
11604 KB |
Output is correct |
9 |
Correct |
233 ms |
13956 KB |
Output is correct |
10 |
Correct |
273 ms |
16044 KB |
Output is correct |
11 |
Correct |
296 ms |
22244 KB |
Output is correct |
12 |
Correct |
367 ms |
25044 KB |
Output is correct |
13 |
Correct |
375 ms |
30216 KB |
Output is correct |
14 |
Correct |
317 ms |
33240 KB |
Output is correct |
15 |
Correct |
392 ms |
39008 KB |
Output is correct |
16 |
Correct |
344 ms |
43724 KB |
Output is correct |
17 |
Correct |
309 ms |
50840 KB |
Output is correct |
18 |
Correct |
364 ms |
57344 KB |
Output is correct |
19 |
Correct |
342 ms |
60756 KB |
Output is correct |
20 |
Correct |
474 ms |
68224 KB |
Output is correct |