网络选拔赛----Shuffle Card

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

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

 

©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页