#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;
struct data{
int ma;
} t[4*N];
int n, m;
void push(int k, int l, int r){
int mid = (l + r)/2;
if(l==r) return ;
t[k*2].ma = max(t[2*k].ma, t[k].ma);
if(t[k].ma)
t[k*2 + 1].ma = max(t[k*2 + 1].ma, t[k].ma + mid - l + 1);
}
void up(int k, int l, int r, int i, int j, int x){
push(k, l, r);
if(r < i || l > j) return ;
if(l >= i && r <= j){
int now = x + l - i;
t[k].ma = max(t[k].ma, now);
push(k, l, r);
return ;
}
int mid = (l + r)/2;
up(k*2, l, mid, i, j, x);
up(k*2 + 1, mid + 1, r, i, j, x);
}
int get1(int k, int l, int r, int i){
push(k, l, r);
if(l==r) return t[k].ma;
int mid = (l + r)/2;
if(i <= mid) return get1(k*2, l, mid, i);
return get1(k*2 + 1, mid + 1, r, i);
}
int main(){
ios_base::sync_with_stdio(0);
cin >> n >> m;
while(m--){
int l, r, x; cin >> l >> r >> x;
up(1, 1, n, l, r, x);
}
f1(i, n) cout << get1(1, 1, n, i) << " ";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
420 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
3 ms |
508 KB |
Output is correct |
5 |
Correct |
4 ms |
628 KB |
Output is correct |
6 |
Correct |
4 ms |
728 KB |
Output is correct |
7 |
Correct |
174 ms |
6424 KB |
Output is correct |
8 |
Correct |
192 ms |
10008 KB |
Output is correct |
9 |
Correct |
207 ms |
13116 KB |
Output is correct |
10 |
Correct |
220 ms |
16692 KB |
Output is correct |
11 |
Correct |
246 ms |
20824 KB |
Output is correct |
12 |
Correct |
246 ms |
24800 KB |
Output is correct |
13 |
Correct |
295 ms |
29224 KB |
Output is correct |
14 |
Correct |
263 ms |
33232 KB |
Output is correct |
15 |
Correct |
295 ms |
38284 KB |
Output is correct |
16 |
Correct |
302 ms |
43076 KB |
Output is correct |
17 |
Correct |
293 ms |
50192 KB |
Output is correct |
18 |
Correct |
318 ms |
55592 KB |
Output is correct |
19 |
Correct |
317 ms |
60572 KB |
Output is correct |
20 |
Runtime error |
367 ms |
66560 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |