2021 年东华大学金马程序设计联赛

D. Move the numbers
PDF 题面可用
你可以在这里下载。

单点时限: 2.0 sec

内存限制: 512 MB

John has learned data structure and algorithm course this semester, and he has a problem in the latest problemset that he desperately needs your help.

Given a permutation a1,a2,,an of 1,2,,n, and the position of the elements will be adjusted m times.

Each adjustment specifies a index k, which means to adjust the array with following operation:

  • First, append all numbers before the k-th number to the end of the array in order.
  • And then, delete all numbers before the k-th number.

Your task is to find the final permutation after m operations.

输入格式

There are multiple test cases in this problem, and the input of each test case are as following statement:

In the first line of each test case, there are two integers n and m (1n,m105) , representing the number of elements in the array and the adjustment times correspondingly.

In the second line of each test case, there is a permutation a1,a2,,an of 1,2,,n, representing the original permutation.

And in the last line of each test case, there are m integers, representing the index k(1kn) of each adjustment.

It is guaranteed that the sum of n over all test cases does not exceed 2×105, and the sum of m over all test cases also does not exceed 2×105.

输出格式

For each test case, output one line which contains n integers (separated by a space), representing the final permutation after m operations.

样例

Input
5 3
1 2 3 4 5
3 2 1
6 2
2 3 4 5 6 1
3 4
Output
4 5 1 2 3
1 2 3 4 5 6