#P6852. Mex
Mex
Description
Little G once had a permutation of to (indices start from ), but he forgot this permutation.
Now he wants to recover it. After trying hard to remember, he can only recall pieces of information about the permutation. Each piece of information is in the form , meaning that the value of the interval is . The value of an interval is the smallest natural number that does not appear in this interval.
Little G tells you and these pieces of information, hoping you can help him restore a permutation, or tell him that something is wrong with his memory.
Input Format
The first line contains two integers and , with the meanings described above.
The next lines each contain three integers describing one piece of information, meaning that the value of the interval is .
Output Format
If there is no permutation that satisfies all conditions, output .
Otherwise, output one line with positive integers, representing a permutation of to .
This problem uses Special Judge. If there are multiple permutations that satisfy the conditions, you may output any one of them.
3 4
0 0 0
0 1 1
0 2 2
1 3 3
3 0 1 2
5 7
0 1 0
4 5 0
1 3 1
0 5 6
0 5 6
2 5 3
2 3 1
4 3 5 0 1 2
Hint
This problem uses bundled tests. You can only get the score of a subtask if you pass all test points in that subtask.
- Subtask 1 (15 points): .
- Subtask 2 (20 points): .
- Subtask 3 (10 points): .
- Subtask 4 (15 points): the testdata is randomly generated.
- Subtask 5 (10 points): .
- Subtask 6 (30 points): no special constraints.
For all testdata: , , .
The testdata generation method for Subtask 4 is: randomly generate a permutation, then randomly choose intervals and compute their values as constraints.
The input and output sizes are large, so please use an efficient I/O method.
Translated by ChatGPT 5
京公网安备 11011102002149号