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>
using namespace std ;
const int MAX = 1e5 + 10 ;
int n , q ;
int L[MAX] , R[MAX] , L2[MAX] , R2[MAX] ;
set<int>s , s2 ;
int ans[MAX] ;
void Exit()
{
for(int i = 0 ; i < n ; ++i)
cout<<-1<<" " ;
exit(0) ;
}
int main()
{
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
cin>>n>>q ;
for(int i = 0 ; i < n ; ++i)
L[i] = R2[i] = -1 , R[i] = L2[i] = 1e9 ;
while(q--)
{
int l , r , x ;
cin>>l>>r>>x ;
L[x] = max(L[x] , l) , R[x] = min(R[x] , r) ;
L2[x] = min(L2[x] , l) , R2[x] = max(R2[x] , r) ;
}
for(int i = 0 ; i < n ; ++i)
s.insert(i) , s2.insert(i) ;
for(int i = n-1 ; i >= 0 ; --i)
{
if(L[i] == -1)
continue ;
if(L[i] > R[i])
Exit() ;
auto it = s.lower_bound(L[i]) ;
if(it == s.end() || (*it) > R[i])
Exit() ;
ans[*it] = i , s.erase(it) , s2.erase(i) ;
while(s.size())
{
it = s.lower_bound(L2[i]) ;
if(it == s.end() || (*it) > R2[i])
break ;
int x = *s2.rbegin() ;
if(x < i)
Exit() ;
ans[*it] = x , s.erase(it) , s2.erase(x) ;
}
}
while(s.size())
{
ans[*s.begin()] = *s2.begin() ;
s.erase(s.begin()) , s2.erase(s2.begin()) ;
}
for(int i = 0 ; i < n ; ++i)
cout<<ans[i]<<" " ;
cout<<"\n" ;
return 0 ;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |