#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define fi first
#define se second
#define ll long long
using namespace std;
const int N = 4e5 + 7;
const int mod = 1e9 + 7;
int n,q;
ll l[N];
ll r[N];
ll z[N];
ll lz[4 * N];
ll t[4 * N];
void push( ll x )
{
if( lz[x] == -1 )return;
t[x * 2] = max( t[x * 2] , lz[x] );
t[x * 2 + 1] = max( t[x * 2 + 1] , lz[x] );
lz[x * 2] = max( lz[x * 2] , lz[x] );
lz[x * 2 + 1] = max( lz[x * 2 + 1] , lz[x] );
lz[x] = -1e18;
}
void upd( int x , int l , int r , int tl , int tr , ll val )
{
if( tl > tr )return;
if( l == tl && r == tr ){
t[x] = max( t[x] , val );
lz[x] = max( lz[x] , val );
return;
}
int m = (l + r) / 2;
push(x);
upd( x * 2 , l , m , tl , min(tr , m) , val );
upd( x * 2 + 1 , m + 1 , r , max(tl , m + 1) , tr , val );
}
ll get( int x , int l , int r , int pos )
{
if( l == r ){
return t[x];
}
int m = (l + r) / 2;
push(x);
if( m >= pos )return get( x * 2 , l , m , pos );
else return get( x * 2 + 1 , m + 1 , r , pos );
}
void solve()
{
cin >> n >> q;
for( int i = 1; i <= 4 * n; i++ ){
t[i] = lz[i] = -1e18;
}
for( int i = 1; i <= q; i++ ){
cin >> l[i] >> r[i] >> z[i];
z[i] -= l[i];
upd( 1 , 1 , n , l[i] , r[i] , z[i] );
}
for( ll i = 1; i <= n; i++ ){
ll ans = get( 1 , 1 , n , i );
if( ans == -1e18 )ans = -i;
cout << ans + i << " ";
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen( "input.txt" , "r" , stdin );
//freopen( "output.txt" , "w" , stdout );
int t = 1;//cin >> t;
while( t-- ){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
6 |
Correct |
4 ms |
632 KB |
Output is correct |
7 |
Correct |
161 ms |
14328 KB |
Output is correct |
8 |
Correct |
178 ms |
15992 KB |
Output is correct |
9 |
Correct |
183 ms |
16616 KB |
Output is correct |
10 |
Correct |
194 ms |
17656 KB |
Output is correct |
11 |
Correct |
210 ms |
19292 KB |
Output is correct |
12 |
Correct |
225 ms |
20088 KB |
Output is correct |
13 |
Incorrect |
243 ms |
21372 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |