AT_abc474_c.Remove and Append
普及-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a permutation P=(P1,P2,…,PN) of (1,2,…,N).
For q=1,2,…,Q in this order, perform the following operation.
- Remove the element with value aq from P, and append it to the end of P.
Find the value of each element of P after performing the Q operations.
给你一个 (1,2,…,N) 的排列 P=(P1,P2,…,PN)。
按 q=1,2,…,Q 的顺序,依次执行以下操作:
- 从 P 中删除值为 aq 的元素,并将其追加到 P 的末尾。
在执行完全部 Q 次操作后,求 P 中每个元素的值。
输入格式
The input is given from Standard Input in the following format:
N Q
P1 P2 … PN
a1
a2
⋮
aQ
输入从标准输入中按以下格式给出:
N Q
P1 P2 … PN
a1
a2
⋮
aQ
输出格式
Output P1,P2,…,PN after performing the Q operations, in this order, separated by spaces, in one line.
执行完 Q 个操作后,按顺序输出 P1,P2,…,PN,以空格分隔,占一行。
输入输出样例
输入#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).
After the first operation, P=(2,4,1,3).
After the second operation, P=(4,1,3,2).
Constraints
- 1≤N≤2×105
- 1≤Q≤2×105
- (P1,P2,…,PN) is a permutation of (1,2,…,N).
- 1≤aq≤N
- All input values are integers.
样例 1 解释:
初始时,P=(2,4,3,1)。
第一次操作后,P=(2,4,1,3)。
第二次操作后,P=(4,1,3,2)。
约束条件
- 1≤N≤2×105
- 1≤Q≤2×105
- (P1,P2,…,PN) 是 (1,2,…,N) 的一个排列。
- 1≤aq≤N
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?