# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
90885 | Aydarov03 | Trading (IZhO13_trading) | C++14 | 2 ms | 376 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>
#define fr first
#define sc second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int N;
int tree[300005 * 4];
pair<int,int> p[300005 * 4];
int n , m , l , r , x;
void upd( int l , int r , int val , int v = 1 , int tl = 1 , int tr = n )
{
if( tl > r || tr < l )return;
if( l <= tl && tr <= r )
{
tree[v] = max( tree[v] , val + ( tl - l ) );;
return;
}
int mid = (tl + tr) / 2;
upd( l , r , val , v + v , tl , mid );
upd( l , r , val , v+v+1 , mid+1 , tr );
}
void get( int l , int r , int v = 1 , int tl = 1 , int tr = n )
{
// cout << tl << " " << tr << endl;
if( p[v].fr || tree[v] )
{
if( tree[v] )
p[v] = {v , tl};
p[v+v] = p[v+v+1] = p[v];
}
if( tl > r || tr < l )return;
if( l <= tl && tr <= r )
{
if( p[v].fr )
cout << tree[ p[v].fr ] + ( -p[v].sc + tl ) << " ";
else
cout << 0 << " ";
return;
}
int mid = (tl + tr) / 2;
get( l , r , v + v , tl , mid );
get( l , r , v+v+1 , mid+1 , tr );
}
main()
{
IOS;
cin >> n >> m;
for(int i = 1; i <= m; i++)
{
cin >> l >> r >> x;
upd( l , r , x );
}
for(int i = 1; i <= n; i++)
get(i , i);
}
/*
5 2
1 3 2
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |