#P5754. [JSOI2010] 排名
[JSOI2010] 排名
Background
On Arbor Day, Little L, Little H, and Little X still had to face a busy exam.
After the exam, as usual, they discussed their scores. Little L was very curious, so he asked all students in the class about their scores. Of course, just as you might expect, nobody wanted to reveal too much: each person only said whose score they were lower than, and some people did not say anything.
Hardworking Little H and lazy Little X each have an “expected ranking” in mind for all students in the class. That is, Little H may think XX should be ranked st, YY should be ranked nd, and so on. But Little X would think XX should be ranked last (the st from the end), YY should be ranked the nd from the end, and so on.
However, ideals and reality always differ. From the information that Little L gathered, XX can no longer be ranked st. Still, Little H believes XX should be ranked as high as possible.
So Little L came up with a question: after Little H and Little X learn the information he gathered, what will their “mental rankings” of the class look like?
Each student’s index is exactly Little H’s mental preference order. In other words, Little H hopes that students with smaller indices will be ranked as high as possible, while Little X hopes that students with smaller indices will be ranked as low as possible (note: this does not mean that students with larger indices should be ranked higher).
Problem Description
Given an array of length , where means that the -th student’s score is lower than the -th student’s score (equivalently, the -th student is ranked after the -th student). Of course, may equal , which means there is no information about the -th student.
You need to obtain an array of length , representing the class ranking. Among all rankings that satisfy all constraints given by , this ranking should be the lexicographically smallest one.
At the same time, you also need to obtain an array , representing the class ranking. Among all rankings that satisfy all constraints given by , this ranking should be the lexicographically largest one.
Input Format
The first line contains a positive integer , the number of students in the class.
The second line contains non-negative integers separated by spaces. The -th number denotes .
Output Format
Output two lines. Each line contains positive integers separated by spaces. The first line is Little H’s mental ranking, and the second line is Little X’s mental ranking.
4
3 0 2 2
3 1 2 4
4 1 3 2
Hint
Sample Explanation
There are rankings that satisfy the ordering constraints:
4 1 3 2
4 1 2 3
3 1 2 4
Among them, 3 1 2 4 is lexicographically smallest, and 4 1 3 2 is lexicographically largest.
Constraints
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, . Among them, the -th testdata group guarantees .
Translated by ChatGPT 5