C. 删除并追加 / Remove and Append

    传统题 2000ms 256MiB

删除并追加 / 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

  • 1≤N≤2×1051 \leq N \leq 2 \times 10^5
  • 1≤Q≤2×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).
  • 1≤aq≤N1 \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

ABC474 赛后模拟赛 ✅

未参加
状态
已结束
规则
IOI
题目
7
开始于
2026-9-6 14:00
结束于
2026-9-20 14:00
持续时间
336 小时
主持人
参赛人数
59