AT_abc474_c Remove and Append
Description
You are given a permutation $ P=(P_1,P_2,\dots,P_N) $ of $ (1,2,\dots,N) $ .
For $ q=1,2,\dots,Q $ in this order, perform the following operation.
- Remove the element with value $ a_q $ from $ P $ , and append it to the end of $ P $ .
Find the value of each element of $ P $ after performing the $ Q $ operations.
Input Format
The input is given from Standard Input in the following format:
> $ N $ $ Q $ $ P_1 $ $ P_2 $ $ \ldots $ $ P_N $ $ a_1 $ $ a_2 $ $ \vdots $ $ a_Q $
Output Format
Output $ P_1,P_2,\dots,P_N $ after performing the $ Q $ operations, in this order, separated by spaces, in one line.
Explanation/Hint
### Sample Explanation 1
Initially, $ P=(2,4,3,1) $ .
After the first operation, $ P=(2,4,1,3) $ .
After the second operation, $ P=(4,1,3,2) $ .
### Constraints
- $ 1 \leq N \leq 2 \times 10^5 $
- $ 1 \leq Q \leq 2 \times 10^5 $
- $ (P_1,P_2,\dots,P_N) $ is a permutation of $ (1,2,\dots,N) $ .
- $ 1 \leq a_q \leq N $
- All input values are integers.