#ABC474C. 删除并追加 / Remove and Append

删除并追加 / Remove and Append

Problem Statement

You are given a permutation P=(P1,P2,,PN)P=(P_1,P_2,\dots,P_N) of (1,2,,N)(1,2,\dots,N). For q=1,2,,Qq=1,2,\dots,Q in this order, perform the following operation.

  • Remove the element with value aqa_q from PP, and append it to the end of PP.

Find the value of each element of PP after performing the QQ operations.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 1Q2×1051 \leq Q \leq 2 \times 10^5
  • (P1,P2,,PN)(P_1,P_2,\dots,P_N) is a permutation of (1,2,,N)(1,2,\dots,N).
  • 1aqN1 \leq a_q \leq N
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

  • NN QQ
  • P1P_1 P2P_2 \dots PNP_N
  • a1a_1
  • a2a_2
  • \vdots
  • aQa_Q

Output

Output P1,P2,,PNP_1,P_2,\dots,P_N after performing the QQ operations, in this order, separated by spaces, in one line.

4 2
2 4 3 1
3
2
4 1 3 2

Initially, P=(2,4,3,1)P=(2,4,3,1). After the first operation, P=(2,4,1,3)P=(2,4,1,3). After the second operation, P=(4,1,3,2)P=(4,1,3,2).

3 3
1 2 3
1
1
1
2 3 1
2 5
2 1
1
1
2
2
1
2 1