妙笔难书一纸愁肠，苍白的誓言，终究抵不过岁月的遗忘。

Problem Description

A deck of card consists of n cards. Each card is different, numbered from 1 to n. At first, the cards were ordered from 1 to n . We complete the shuffle process in the following way, In each operation, we will draw a card and put it in the position of the first card, and repeat this operation for m times.

Please output the order of cards after m operations.

Input

The first line of input contains two positive integers n and m .（1<=n,m <=105 ）

The second line of the input file has n Numbers, a sequence of 1 through n .

Next there are m rows, each of which has a positive integer si , representing the card number extracted by the i -th operation.

Output

Please output the order of cards after m operations. (There should be one space after each number.)

Sample Input



5 3 1 2 3 4 5 3 4 3

Sample Output



3 4 1 2 5

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int N,M,vis[200010],s[100010],ss[100010];
int main()
{
cin>>N>>M;
for(int i=0; i<N; i++)
cin>>s[i];
for(int i=0; i<M; i++)
cin>>ss[i];
for(int i=M-1; i>=0; i--)
{
if(!vis[ss[i]])
{
cout<<ss[i]<<' ';
vis[ss[i]]=1;
}
}
for(int i=0; i<N; i++)
{
if(!vis[s[i]])
cout<<s[i]<<' ';
}
return 0;
}
//12 6
//12 3 4 5 6 7 8 9 10 11 1 13
//3
//5
//7
//1
//7
//9
//9 7 1 5 3 12 4 6 8 10 11 13

• 点赞 1
• 评论 3
• 分享
x

海报分享

扫一扫，分享海报

• 收藏
• 手机看

分享到微信朋友圈

x

扫一扫，手机阅读

• 打赏

打赏

0k-ok

你的鼓励将是我创作的最大动力

C币 余额
2C币 4C币 6C币 10C币 20C币 50C币
• 一键三连

点赞Mark关注该博主, 随时了解TA的最新博文