시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 1024 MB24121254.545%

문제

You are given a list of integers $x_1, x_2, \ldots, x_n$ and a number $k$. It is guaranteed that each $i$ from $1$ to $k$ appears in the list at least once.

Find the lexicographically smallest subsequence of $x$ that contains each integer from $1$ to $k$ exactly once.

입력

The first line will contain two integers $n$ and $k$, with $1\le k\le n\le 200\,000$. The following $n$ lines will each contain an integer $x_i$ with $1\le x_i\le k$.

출력

Write out on one line, separated by spaces, the lexicographically smallest subsequence of $x$ that has each integer from $1$ to $k$ exactly once.

예제 입력 1

6 3
3
2
1
3
1
3

예제 출력 1

2 1 3

예제 입력 2

10 5
5
4
3
2
1
4
1
1
5
5

예제 출력 2

3 2 1 4 5

출처

ICPC > Regionals > North America > North Central North America Regional > NCNA 2019 E번

  • 문제를 만든 사람: Lewin Gan