#P7707. [2019年杭电多校]find hidden array
[2019年杭电多校]find hidden array
find hidden array
Problem Description
You are given an integer . There is a hidden array of size containing a permutation of . There is an empty set. Initially, the first integers of this array are inserted into the set. Then, there are operations performed. The -th operation is one of the following two actions:
- take out the LARGEST number from the set, and then insert the -th number from the array into the set.
- take out the SMALLEST number from the set, and then insert the -th number from the array into the set. For each operation, you only know which action is taken and what's the number taken out from the set. Please find out the content of the hidden array based on the given information. If there are many possible such arrays, you must output the lexicographically smallest one.
Input
The first line contains an integer indicating there are tests. Each test consists of two lines. the first line contains one positive integer indicating that the size of the hidden array is . The second line contains integers describe the operations. For the -th operation, the LARGEST number with value is taken out from the set if is positive; Otherwise, is negative which means the SMALLEST number with value is taken out from the set in the -th operation.
- sum of all across tests
- are all distinct in a test
Output
For each test, if it's impossible to recover such array, output a single integer in a line. Otherwise, output positive integers, indicating the array you recovered. If there are multiple ways, you should choose the lexicographically smallest one.
Sample Input
4
3
-1 4 -2
1
2
2
-4 3
4
-2 8 6 -3
Sample Output
1 2 3 4 5 6
2 1
-1
2 3 4 5 8 6 7 1
Source
2019 Multi-University Training Contest 5