#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int MAX_N = 1e6;
const int INF = 1e9;
const int mod = 1e9 + 7;
#ifndef LOCAL
#define cerr if(false) cerr
#endif
std::vector<std::pair<int, int>> Q[MAX_N];
std::set<int> pos;
std::set<int> nums;
bool use[MAX_N];
int nas[MAX_N];
int main () {
#ifndef LOCAL
std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
#endif
int n, q;
std::cin>>n>>q;
for( int i=0 ; i<q ; i++ ){
int a, b, c;
std::cin>>a>>b>>c;
Q[c].push_back({a, b});
}
for( int i=0 ; i<n ; i++ ){
pos.insert(i);
nums.insert(i);
}
bool oke = true;
for( int i=n-1 ; i>=0 ; i-- ){
if( Q[i].size() == 0 ) continue;
int smMin = 0, smMax = n-1;
int bgMin = n-1, bgMax =0;
for( auto j : Q[i] ){
smMin = std::max( smMin, j.first );
smMax = std::min( smMax, j.second );
bgMin = std::min( bgMin, j.first );
bgMax = std::max( bgMax, j.second );
}
//std::cerr<<smMin<<" "<< smMax<<" , "<<bgMin<<" "<<bgMax<<"\n";
if( smMax < smMin ){
oke = false;
break;
}
auto it = pos.lower_bound( smMin );
if( it == pos.end() || *it > smMax ){
oke = false;
break;
}
if( nums.find(i) == nums.end() ){
oke = false;
break;
}
//std::cerr<<" ! "<<i<<"\n";
nas[*it] = i;
use[*it] = true;
//if( nums.find( i ) == nums.end() ) std::cerr<<" chep \n";
//std::cerr<<" erase :"<<i<<"\n";
nums.erase( i );
pos.erase( it );
while( true ){
auto curr = pos.lower_bound( bgMin );
if( curr == pos.end() || *curr > bgMax ) break;
//std::cerr<<*curr<<" , ";
if( *nums.rbegin() < i ){
oke = false;
break;
}
use[*curr] = true;
pos.erase( curr );
nas[*curr] = *nums.rbegin();
nums.erase( *nums.rbegin() );
}
if( !oke ) break;
}
if( !oke ){
for( int i=0 ; i<n ; i++ ) std::cout<<"-1 ";
std::cout<<"\n";
return 0;
}
for( int i=0 ; i<n ; i++ ){
if( !use[i] ){
nas[i] = *nums.rbegin();
nums.erase( *nums.rbegin() );
}
}
for( int i = 0; i<n ; i++ ) std::cout<<nas[i]<<" ";
std::cout<<"\n";
return 0;
}
// i dont know, where i'm going, but i hope that i'm on the right path
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
14 ms |
23756 KB |
Output is correct |
3 |
Correct |
13 ms |
23808 KB |
Output is correct |
4 |
Correct |
13 ms |
23764 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
14 ms |
23804 KB |
Output is correct |
7 |
Correct |
13 ms |
23732 KB |
Output is correct |
8 |
Correct |
13 ms |
23764 KB |
Output is correct |
9 |
Correct |
14 ms |
23764 KB |
Output is correct |
10 |
Correct |
14 ms |
23764 KB |
Output is correct |
11 |
Correct |
13 ms |
23764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
14 ms |
23756 KB |
Output is correct |
3 |
Correct |
13 ms |
23808 KB |
Output is correct |
4 |
Correct |
13 ms |
23764 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
14 ms |
23804 KB |
Output is correct |
7 |
Correct |
13 ms |
23732 KB |
Output is correct |
8 |
Correct |
13 ms |
23764 KB |
Output is correct |
9 |
Correct |
14 ms |
23764 KB |
Output is correct |
10 |
Correct |
14 ms |
23764 KB |
Output is correct |
11 |
Correct |
13 ms |
23764 KB |
Output is correct |
12 |
Correct |
14 ms |
23804 KB |
Output is correct |
13 |
Correct |
13 ms |
23816 KB |
Output is correct |
14 |
Correct |
13 ms |
23832 KB |
Output is correct |
15 |
Correct |
13 ms |
23936 KB |
Output is correct |
16 |
Correct |
14 ms |
24052 KB |
Output is correct |
17 |
Correct |
12 ms |
23892 KB |
Output is correct |
18 |
Correct |
13 ms |
23892 KB |
Output is correct |
19 |
Correct |
13 ms |
23880 KB |
Output is correct |
20 |
Correct |
14 ms |
23804 KB |
Output is correct |
21 |
Correct |
15 ms |
23788 KB |
Output is correct |
22 |
Correct |
14 ms |
23816 KB |
Output is correct |
23 |
Correct |
13 ms |
23892 KB |
Output is correct |
24 |
Correct |
13 ms |
23892 KB |
Output is correct |
25 |
Correct |
13 ms |
23744 KB |
Output is correct |
26 |
Correct |
14 ms |
23704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
14 ms |
23756 KB |
Output is correct |
3 |
Correct |
13 ms |
23808 KB |
Output is correct |
4 |
Correct |
13 ms |
23764 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
14 ms |
23804 KB |
Output is correct |
7 |
Correct |
13 ms |
23732 KB |
Output is correct |
8 |
Correct |
13 ms |
23764 KB |
Output is correct |
9 |
Correct |
14 ms |
23764 KB |
Output is correct |
10 |
Correct |
14 ms |
23764 KB |
Output is correct |
11 |
Correct |
13 ms |
23764 KB |
Output is correct |
12 |
Correct |
14 ms |
23804 KB |
Output is correct |
13 |
Correct |
13 ms |
23816 KB |
Output is correct |
14 |
Correct |
13 ms |
23832 KB |
Output is correct |
15 |
Correct |
13 ms |
23936 KB |
Output is correct |
16 |
Correct |
14 ms |
24052 KB |
Output is correct |
17 |
Correct |
12 ms |
23892 KB |
Output is correct |
18 |
Correct |
13 ms |
23892 KB |
Output is correct |
19 |
Correct |
13 ms |
23880 KB |
Output is correct |
20 |
Correct |
14 ms |
23804 KB |
Output is correct |
21 |
Correct |
15 ms |
23788 KB |
Output is correct |
22 |
Correct |
14 ms |
23816 KB |
Output is correct |
23 |
Correct |
13 ms |
23892 KB |
Output is correct |
24 |
Correct |
13 ms |
23892 KB |
Output is correct |
25 |
Correct |
13 ms |
23744 KB |
Output is correct |
26 |
Correct |
14 ms |
23704 KB |
Output is correct |
27 |
Correct |
75 ms |
33072 KB |
Output is correct |
28 |
Correct |
79 ms |
33800 KB |
Output is correct |
29 |
Correct |
75 ms |
33232 KB |
Output is correct |
30 |
Correct |
88 ms |
34420 KB |
Output is correct |
31 |
Correct |
69 ms |
31936 KB |
Output is correct |
32 |
Correct |
67 ms |
31844 KB |
Output is correct |
33 |
Correct |
64 ms |
32204 KB |
Output is correct |
34 |
Correct |
44 ms |
29592 KB |
Output is correct |
35 |
Correct |
71 ms |
33640 KB |
Output is correct |
36 |
Correct |
70 ms |
34976 KB |
Output is correct |
37 |
Correct |
73 ms |
35276 KB |
Output is correct |
38 |
Correct |
42 ms |
30156 KB |
Output is correct |
39 |
Correct |
69 ms |
33592 KB |
Output is correct |
40 |
Correct |
14 ms |
23716 KB |
Output is correct |
41 |
Correct |
12 ms |
23808 KB |
Output is correct |