insertion sort problem

insertion sort

[Problem description]
lzz learned insertion sort today, he thinks insertion sort is very interesting. Now he has a sequence of length n, and there are no identical numbers in this sequence. Now he wants to perform m operations on this sequence. For each operation, he will select an element x in a sequence, and then he can choose to take x out of the sequence and put it at the end of the sequence; or take out x, then output the sequence in order, and then insert x into the original Location. But he hasn't done it for a long time, so he invites you to complete this task.
[Input form]
Input an integer n in the first line.
The second line inputs n integers in sequence, representing the sequence of lzz.
The third line enters an integer m.
In the next m lines, there are two integers a and b in each line. If a=0, it means that lzz will take out b and put it at the end of the sequence; if a=1, it means that lzz will take out b and output it, and then put b put it back. (1<=n,m<=5000)
[Output format]
For each a=1, output one line.
There are n-1 integers in each line, indicating that lzz has taken out the sequence after b.
[Sample input]
10
1 2 3 4 5 6 7 8 9 10 5
0
5
1 10
1 7
0 9
1 8
[Sample output]
1 2 3 4 6 7 8 9 5
1 2 3 4 6 8 9 10 5
1 2 3 4 6 7 10 5 9
[Example Description]
1<=n,m<=5

Guess you like

Origin blog.csdn.net/m0_68111267/article/details/130167866