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. 洛谷 P2662 牛场围栏

    做法是这样的: 首先暴力把所有可能的边长搞出来..(当然<=0的不要) 排序边长+去重, 当且仅当可行边长里面有1时,任何长度都能取到,输出-1 当且仅当所有可行边长的gcd大于1时,不能取到的 ...

  2. struts2的@Result annotation 如何添加params,并且在页面取值

    http://www.bubuko.com/infodetail-2492575.html .............................................. 标签:lai  ...

  3. ASP.NET页面传值的方法

    ASP.NET页面传值的方法 From:Refresh-air 在面试的时候,经常会遇到这样的问题,其实我们会对其中的几种方法比较熟悉,因为项目中经常使用.但是要全面的回答ASP.NET中页面传值的方 ...

  4. 闹心的CSDN

    近来搜索技术文章时,每次来到csdn上时,显示全文就提示登陆. 唉登陆就登陆吧,记不清账号了,就用手机号获取验证码.然后更改密码.我靠,密码居然要8位以上,要有大小写字母.数字和标点符号的组合... ...

  5. LR中webservice服务测试的脚本

    Action(){ /* 测试QQ是否在线的功能接口 输入参数:QQ号码 String,默认QQ号码:8698053. 返回数据:String,Y = 在线:N = 离线:E = QQ号码错误:A = ...

  6. COGS 133. [USACO Mar08] 牛跑步

    ★★★   输入文件:cowjog.in   输出文件:cowjog.out   简单对比时间限制:1 s   内存限制:128 MB Bessie准备用从牛棚跑到池塘的方法来锻炼. 但是因为她懒,她 ...

  7. 洛谷 P2362 围栏木桩

    题目描述 某农场有一个由按编号排列的n根木桩构成的首尾不相连的围栏.现要在这个围栏中选取一些木桩,按照原有的编号次序排列之后,这些木桩高度成一个升序序列.所谓的升序序列就是序列中的任何一个数都不小于它 ...

  8. Servlet和JSP之自定义标签学习

      此文章会讲述简单标签处理器,因为经典自定义标签处理器没有简单标签处理器方便使用,故在此不进行描述. 参考:慕课网的<JSP自定义标签>视频; <Servlet.JSP和Sprin ...

  9. 在Windows笔记本上调试运行在iOS设备上的前端应用

    我在每天工作中需要在不同的移动设备上测试我们开发的前端应用是否正常工作,比如iOS设备和Android设备.我用的工作笔记本电脑又是Lenovo的,安装的是Windows操作系统. 有的时候一个开发好 ...

  10. HtmlUnit爬取Ajax动态生成的网页以及自动调用页面javascript函数

    HtmlUnit官网的介绍: HtmlUnit是一款基于Java的没有图形界面的浏览器程序.它模仿HTML document并且提供API让开发人员像是在一个正常的浏览器上操作一样,获取网页内容,填充 ...