Logo
(追記) (追記ここまで)

13399번 - Rearranging a Sequence 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB41024820060.606%

문제

You are given an ordered sequence of integers, (1, 2, 3, . . . , n). Then, a number of requests will be given. Each request specifies an integer in the sequence. You need to move the specified integer to the head of the sequence, leaving the order of the rest untouched. Your task is to find the order of the elements in the sequence after following all the requests successively.

입력

The input consists of a single test case of the following form.

n m
e1
.
.
.
em

The integer n is the length of the sequence (1 ≤ n ≤ 200000). The integer m is the number of requests (1 ≤ m ≤ 100000). The following m lines are the requests, namely e1, . . . , em, one per line. Each request ei (1 ≤ i ≤ m) is an integer between 1 and n, inclusive, designating the element to move. Note that, the integers designate the integers themselves to move, not their positions in the sequence.

출력

Output the sequence after processing all the requests. Its elements are to be output, one per line, in the order in the sequence.

제한

예제 입력 1

5 3
4
2
5

예제 출력 1

5
2
4
1
3

예제 입력 2

10 8
1
4
7
3
4
10
1
3

예제 출력 2

3
1
10
4
7
2
5
6
8
9

힌트

In Sample Input 1, the initial sequence is (1, 2, 3, 4, 5). The first request is to move the integer 4 to the head, that is, to change the sequence to (4, 1, 2, 3, 5). The next request to move the integer 2 to the head makes the sequence (2, 4, 1, 3, 5). Finally, 5 is moved to the head, resulting in (5, 2, 4, 1, 3).

출처

ICPC > Regionals > Asia Pacific > Japan > Asia Regional Contest 2016 in Tsukuba A번

Camp > Petrozavodsk Programming Camp > Winter 2017 > Day 8: Japanese Contest A번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /