#P6721. [BalkanOI 2011] medians

    ID: 7499 远端评测题 300ms 64MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2011Special JudgeBalkanOI(巴尔干半岛)

[BalkanOI 2011] medians

Problem Description

Let AA be any permutation of 1,2,3,,2×N11,2,3,\ldots,2\times N-1.

We define the prefix medians of AA as a sequence BB of length NN, where BiB_i is the median of A1,A2,,A2×i1A_1,A_2,\ldots,A_{2\times i-1}.

You will be given the sequence BB. Please construct a sequence AA such that its prefix medians are exactly BB.

Input Format

The first line contains an integer NN.

The next line contains NN integers, representing the sequence BB.

Output Format

Output one line with 2×N12\times N-1 integers, representing the sequence AA you construct.

The testdata is guaranteed to have a solution; you only need to output any one valid solution.

5
1 3 3 4 5

1 9 3 2 4 8 7 5 6

Hint

Constraints

  • For 60%60\% of the testdata, it is guaranteed that N103N\le 10^3.
  • For 100%100\% of the testdata, it is guaranteed that 1N1051\le N\le 10^5, 1Ai,Bi2×N11\le A_i,B_i\le 2\times N-1, and the testdata is guaranteed to have a solution.

Notes

This problem is translated from Balkan Olympiad in Informatics 2011 Day 1 T3 medians.

Thanks to

https://www.luogu.com.cn/user/193198
ing the SPJ.

Translated by ChatGPT 5