Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Solaris 11.2 System Administration (oracle Press)

Authors: Harry Foxwell

1st Edition

007184421X, 9780071844215

More Books

Students also viewed these Databases questions