#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 ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
0 ms |
332 KB |
Output is correct |
26 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
0 ms |
332 KB |
Output is correct |
26 |
Correct |
0 ms |
332 KB |
Output is correct |
27 |
Correct |
60 ms |
8304 KB |
Output is correct |
28 |
Correct |
66 ms |
9740 KB |
Output is correct |
29 |
Correct |
60 ms |
9416 KB |
Output is correct |
30 |
Correct |
68 ms |
10200 KB |
Output is correct |
31 |
Correct |
52 ms |
7708 KB |
Output is correct |
32 |
Correct |
59 ms |
7236 KB |
Output is correct |
33 |
Correct |
54 ms |
9856 KB |
Output is correct |
34 |
Correct |
33 ms |
6812 KB |
Output is correct |
35 |
Correct |
61 ms |
11332 KB |
Output is correct |
36 |
Correct |
57 ms |
10684 KB |
Output is correct |
37 |
Correct |
57 ms |
10052 KB |
Output is correct |
38 |
Correct |
43 ms |
7624 KB |
Output is correct |
39 |
Correct |
63 ms |
9796 KB |
Output is correct |
40 |
Correct |
0 ms |
332 KB |
Output is correct |
41 |
Correct |
0 ms |
204 KB |
Output is correct |