A family of nn gnomes likes to line up for a group picture. Each gnome can be uniquely identified by a number 1..n1..n written on their hat.

Suppose there are 55 gnomes. The gnomes could line up like so: 1, 3, 4, 2, 51,3,4,2,5.

Now, an evil magician will remove some of the gnomes from the lineup and wipe your memory of the order of the gnomes. The result is a subsequence, perhaps like so: 1, 4, 21,4,2.

He then tells you that if you ordered all permutations of 1..n1..n in lexicographical order, the original sequence of gnomes is the first such permutation which contains the remaining subsequence. Your task is to find the original sequence of gnomes.

Input Format

Each input will consist of a single test case.

Note that your program may be run multiple times on different inputs.

Each test case will begin with a line with two integers nn and then m (1 \le m \le n \le 10^5)m(1≤m≤n≤105), where nn is the number of gnomes originally, and mm is the number of gnomes remaining after the evil magician pulls his trick. Each of the next mm lines will contain a single integer g (1 \le g \le n)g(1≤g≤n). These are the remaining gnomes, in order. The values of gg are guaranteed to be unique.

Output Format

Output nn lines, each containing a single integer, representing the first permutation of gnomes that could contain the remaining gnomes in order.

样例输入1

5 3
1
4
2

样例输出1

1
3
4
2
5

样例输入2

7 4
6
4
2
1

样例输出2

3
5
6
4
2
1
7

题目来源

The North American Invitational Programming Contest 2018

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <string>
#include <deque>
using namespace std;
#define ll long long
#define N 100009
#define gep(i,a,b) for(int i=a;i<=b;i++)
#define gepp(i,a,b) for(int i=a;i>=b;i--)
#define gep1(i,a,b) for(ll i=a;i<=b;i++)
#define gepp1(i,a,b) for(ll i=a;i>=b;i--)
#define mem(a,b) memset(a,b,sizeof(a))
int n,m;
bool vis[N];
int a[N];
int main()
{
scanf("%d%d",&n,&m);
int pos=;
int x;
gep(i,,m){
scanf("%d",&a[i]);
vis[a[i]]=;
}
int j;
gep(i,,m){
for(j=pos;j<=a[i];j++){
if(!vis[j]){
vis[j]=;
printf("%d\n",j);
}
}
pos=j;
printf("%d\n",a[i]);
}
gep(i,,n){
if(!vis[i]){
printf("%d\n",i);
}
}
return ;
}

The North American Invitational Programming Contest 2018 D. Missing Gnomes的更多相关文章

  1. The North American Invitational Programming Contest 2018 H. Recovery

    Consider an n \times mn×m matrix of ones and zeros. For example, this 4 \times 44×4: \displaystyle \ ...

  2. The North American Invitational Programming Contest 2018 E. Prefix Free Code

    Consider nn initial strings of lower case letters, where no initial string is a prefix of any other ...

  3. North American Invitational Programming Contest 2018

    A. Cut it Out! 枚举第一刀,那么之后每切一刀都会将原问题划分成两个子问题. 考虑DP,设$f[l][r]$表示$l$点顺时针一直到$r$点还未切割的最小代价,预处理出每条边的代价转移即可 ...

  4. The North American Invitational Programming Contest 2017 题目

    NAIPC 2017 Yin and Yang Stones 75.39% 1000ms 262144K   A mysterious circular arrangement of black st ...

  5. North American Invitational Programming Contest (NAIPC) 2017

    (待补) A. Pieces of Parentheses 将括号处理完成后排序,方式参加下面的博客.然后做一遍背包即可. 2018 Multi-University Training Contest ...

  6. North American Invitational Programming Contest (NAIPC) 2016

    (待补) A. Fancy Antiques 爆搜. B. Alternative Bracket Notation C. Greetings! D. Programming Team 0/1分数规划 ...

  7. AtCoder SoundHound Inc. Programming Contest 2018 E + Graph (soundhound2018_summer_qual_e)

    原文链接https://www.cnblogs.com/zhouzhendong/p/AtCoder-SoundHound-Inc-Programming-Contest-2018-E.html 题目 ...

  8. ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syria, Lattakia, Tishreen University, April, 30, 2018

    ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syr ...

  9. German Collegiate Programming Contest 2018​ B. Battle Royale

    Battle Royale games are the current trend in video games and Gamers Concealed Punching Circles (GCPC ...

随机推荐

  1. [coci2015-2016 coii] Palinilap【字符串 哈希】

    传送门:http://www.hsin.hr/coci/archive/2015_2016/ 进去之后点底下的那个.顺带说一句,题目既不是一个英文单词,也不是克罗地亚单词,估计只是从回文串的英文单词p ...

  2. Elasticsearch之安装

    elasticsearch需要java8以上支持 java -version 二进制文件下载 www.elastic.co/downloads tar安装示例 1.下载tar文件 curl -L -O ...

  3. [已读]JavaScript DOM编程艺术

    看到过很多人将它作为推荐入门书籍,当时我刚看完ppk和javascript精粹,于是看到这本就觉得很一般了.怎么说,它适合基础.

  4. centos7安装文档

    1.当载入安装镜像时,我们会看到如下图中的画面,我们选择第一项,安装centos7 2.选择英语(个人测试环境可以使用中文安装) 3.选择network&hostname配置网络 4.在配置网 ...

  5. Negut 上传乱码

    解决办法 修改 bat  文件的 格式为ANSI格式即可

  6. .Net魔兽登录页面

    一,页面部分展示 二.代码展示 1.登录页面: public partial class FrmLogin : Form { public FrmLogin() { InitializeCompone ...

  7. CentOS 6.5 下,phpmyadmin 建库无权限

    阿里云主机.用root进入phpMyadmin,居然没有权限建库. 上网查到命令: grant all privileges on *.* to root@'%' identified by &quo ...

  8. LightOJ 1422 Halloween Costumes (区间DP,经典)

    题意: 有个人要去参加万圣节趴,但是每到一个趴都要换上特定的服装,给定一个序列表示此人要穿的衣服编号(有先后顺序的),他可以套很多件衣服在身上,但此人不喜欢再穿那些脱下的衣服(即脱下后就必须换新的), ...

  9. UVA 10572 Black & White (状压DP)

    题意:有一个n*m的矩阵,其中部分格子已经涂黑,部分涂白,要求为其他格子也上黑/白色,问有多少种涂法可以满足一下要求: (1)任意2*2的子矩阵不可以同色. (2)所有格子必须上色. (3)只能有两个 ...

  10. 模拟水题之unique两行AC

    https://icpc.njust.edu.cn/Contest/749/A/ Description 小鱼喜欢吃糖果.他有两盒糖果,两盒糖果分别仅由小写字母组成的字符串s和字符串t构成.其中'a' ...