Question: please answer this question with c++ code and cin the input not input test case Description For a given permutation of 1n, noting it as

 please answer this question with c++ code and cin the input

please answer this question with c++ code and cin the input not input test case

Description For a given permutation of 1n, noting it as P, you need to insert the number in P into a set S one by one, i.e. P1,P2,,Pn1,Pn. After the insertion of each number, you need to find the largest number in S that is smaller than the inserted number and the smallest number in S that is larger than the inserted number. Initially, two integers 0,n+1 has already been inserted into S so that the results always exist. Input The input contains multiple test cases. The first line of the input contains an integer T, indicating the number of test cases. For each test case, the first line contains a positive integer n. The second line contains n integers, separated by spaces, the i-th integer of which denotes Pi. Output For each test case, print n lines, each line contains two integers separated by a space, the i-th line of which denotes the result required after the insertion of the i-th number. The first integer of a result represents the largest number in S that is smaller than the inserted number and the second one represents the smallest number in S that is larger than the inserted numbser. Sample Input/Output Input 5 15243 Output 06 16 15 25 24 Constraint 1n105. It is guaranteed that P is a permutation of 1n. Hint To find all the results quickly enough, you may think about reverting the whole process

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!