AT_abc474_c.Remove and Append

普及-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

给你一个 (1,2,…,N)(1,2,\dots,N) 的排列 P=(P1,P2,…,PN)P=(P_1,P_2,\dots,P_N)。
按 q=1,2,…,Qq=1,2,\dots,Q 的顺序,依次执行以下操作:

  • 从 PP 中删除值为 aqa_q 的元素,并将其追加到 PP 的末尾。

在执行完全部 QQ 次操作后,求 PP 中每个元素的值。

输入格式

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

NN QQ
P1P_1 P2P_2 …\ldots PNP_N
a1a_1
a2a_2
⋮\vdots
aQa_Q

输入从标准输入中按以下格式给出:

NN QQ
P1P_1 P2P_2 …\ldots PNP_N
a1a_1
a2a_2
⋮\vdots
aQa_Q

输出格式

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

执行完 QQ 个操作后,按顺序输出 P1,P2,…,PNP_1,P_2,\dots,P_N,以空格分隔,占一行。

输入输出样例

  • 输入#1

    4 2
    2 4 3 1
    3
    2

    输出#1

    4 1 3 2
  • 输入#2

    3 3
    1 2 3
    1
    1
    1

    输出#2

    2 3 1
  • 输入#3

    2 5
    2 1
    1
    1
    2
    2
    1

    输出#3

    2 1

说明/提示

Sample 1 Explanation:
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).

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.

样例 1 解释:
初始时,P=(2,4,3,1)P=(2,4,3,1)。
第一次操作后,P=(2,4,1,3)P=(2,4,1,3)。
第二次操作后,P=(4,1,3,2)P=(4,1,3,2)。

约束条件

  • 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) 是 (1,2,…,N)(1,2,\dots,N) 的一个排列。
  • 1≤aq≤N1 \leq a_q \leq N
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页