#P5754. [JSOI2010] 排名

[JSOI2010] 排名

Description

Given an array AA of length NN, where AiA_i means that the ii-th student’s score is lower than the AiA_i-th student’s score (equivalently, the ii-th student is ranked after the AiA_i-th student). Of course, AiA_i may equal 00, which means there is no information about the ii-th student.

You need to obtain an array HH of length NN, representing the class ranking. Among all rankings that satisfy all constraints given by AiA_i, this ranking should be the lexicographically smallest one.

At the same time, you also need to obtain an array XX, representing the class ranking. Among all rankings that satisfy all constraints given by AiA_i, this ranking should be the lexicographically largest one.

Input Format

The first line contains a positive integer NN, the number of students in the class.

The second line contains NN non-negative integers separated by spaces. The ii-th number denotes AiA_i.

Output Format

Output two lines. Each line contains NN 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 33 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 10%10\% of the testdata, N10N\leq 10.

For 20%20\% of the testdata, N20N\leq 20.

For 40%40\% of the testdata, N2×103N\leq 2\times 10^3.

For 100%100\% of the testdata, 1N2×105,AiN1 \leq N\leq 2\times 10^5, A_i\leq N. Among them, the 55-th testdata group guarantees N=1.2×104N=1.2\times 10^4.

Translated by ChatGPT 5