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. RESTful架构搜集

    今天才知道RESTful这个词,感觉好落后呀.自从5月份后很少学习新知识,这是个不好的信号. RESTful是Representational State Transfer的缩写.怎么理解Repres ...

  2. AmazeUI 保存浏览器数据 永久性

    //保存永久缓存数据function SaveAmuiStore(ItemName, ItemData){ if (window.localStorage) { var store = $.AMUI. ...

  3. Java GUI 顶级容器JFrame、JDialog

    JFrame的常用构造函数: JFrame() JFrame(String title)   //窗口标题,会显示在左上角窗体图标的后面 JDialog的常用构造函数: JDialog() JDial ...

  4. 惊人的CSS和JavaScript动画logos例子

    https://codepen.io/lindell/pen/mEVgJP Stack Overflow logo是我最喜欢的logo之一,因为它非常简单,但易于识别.并且这个片段动画点击预览Stac ...

  5. 2013上半年中国CRM市场分析报告

    经过了十多年的风风雨雨,CRM度过了漫长的市场培育期,即将迎来成熟期.目前这一阶段也是CRM惨烈搏杀的一个阶段,据不完全统计,国内大大小小的CRM厂商已经超过600家,各厂商几度火拼,努力扩大自己在C ...

  6. Objective-C Log Handling

    NSLog method In order to print logs, we use the NSLog method in Objective-C programming language whi ...

  7. uvm_reg_model——寄存器模型(一)

    对于一个复杂设计,寄存器模型要能够模拟任意数量的寄存器域操作.UVM提供标准的基类库,UVM的寄存器模型来自于继承自VMM的RAL(Register Abstract Layer),现在可以先将寄存器 ...

  8. MSSQL复制表

    -复制表结构有句型的--跨数据库 --复制结构+数据 select * into 数据库名.dbo.新表名 from 数据库名.dbo.原表名 --只复制结构 select * into 数据库名.d ...

  9. ubuntu 14.04 配置java 1.8环境变量

    从官网上下载jdk 源文件,并解压 root@hett-PowerEdge-T30:/usr/local/src# tar -xzvf jdk-8u151-linux-x64.tar.gz 解压完成之 ...

  10. 欧拉回路/通路 Codeforces Round #288 (Div. 2)

    http://codeforces.com/contest/508/problem/D 以上是题目链接 题目大意 给n个字符串看能不能链接在一起 因为 三个三个分割 所以字符串 如abc ab作为起点 ...