#P16130. [ICPC 2018 NAIPC] Missing Gnomes

[ICPC 2018 NAIPC] Missing Gnomes

题目描述

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

Suppose there are 5 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 1n1\dots 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.

输入格式

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 mm (1mn1051 \leq m \leq n \leq 10^5), 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 gg (1gn1 \leq g \leq n). These are the remaining gnomes, in order. The values of gg are guaranteed to be unique.

输出格式

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

5 3
1
4
2
1
3
4
2
5
7 4
6
4
2
1
3
5
6
4
2
1
7