# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
168542 | muhammad_hokimiyon | Trading (IZhO13_trading) | C++14 | 226 ms | 15608 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
int l[N];
int r[N];
int z[N];
int lz[4 * N];
int t[4 * N];
void push( int 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] = -1e9;
}
void upd( int x , int l , int r , int tl , int tr , int 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 );
}
int 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] = -1e9;
}
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( int i = 1; i <= n; i++ ){
int ans = get( 1 , 1 , n , i );
if( ans == -1e9 )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 |
---|---|---|---|---|
Fetching results... |