Question: Sorting Description For a given permutation of , noting it as , you need to insert the number in into a set one by one,
Sorting
Description
For a given permutation of noting it as you need to insert the number in into a set
one by one, ie
After the insertion of each number, you need to find the largest number in that is smaller than
the inserted number and the smallest number in that is larger than the inserted number.
Initially, two integers has already been inserted into so that the results always exist.
Input
The input contains multiple test cases. The first line of the input contains an integer indicating
the number of test cases.
For each test case, the first line contains a positive integer The second line contains
integers, separated by spaces, the th integer of which denotes
Output
For each test case, print lines, each line contains two integers separated by a space, the th
line of which denotes the result required after the insertion of the th number.
The first integer of a result represents the largest number in that is smaller than the inserted
number and the second one represents the smallest number in that is larger than the inserted
numbser.
Sample InputOutput
Input
Output
n P P
S P P Pn Pn
S
S
n S
T
n n
i Pi
n i
i
S
S
Constraint
It is guaranteed that is a permutation of
Hint
To find all the results quickly enough, you may think about reverting the whole process.
n
P n
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
