아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Stone Arranging 2

시간 제한2초메모리 제한1024 MB

요약
돌을 하나씩 오른쪽에 놓을 때마다 같은 색의 가장 가까운 이전 돌 이후 구간을 그 색으로 칠하고, 마지막 색을 출력한다.
난이도

보통10점 중 6점

유형
스택, 구현, 배열, 해시맵
정답자
아직 제출이 없습니다

문제

JOI-kun has NN go stones. The stones are numbered from 11 to NN. The color of each stone is an integer between 11 and 10910^9, inclusive. In the beginning, the color of Stone ii (1≤i≤N1 ≤ i ≤ N) is A_iA\_i.

From now, JOI-kun will perform NN operations. He will put the stones on the table in a line. The operation ii (1≤i≤N1 ≤ i ≤ N) will be performed as follows:

  1. JOI-kun will put Stone ii on the immediate right of Stone i−1i - 1. However, when i=1i = 1, JOI-kun will put Stone 11 on the table.
  2. If there is a stone among Stones 11, 22, …\dots, i−1i - 1 whose current color is the same as Stone ii, let jj be the maximum index of such stones, and JOI-kun will paint all of Stones j+1j + 1, j+2j + 2, …\dots, i−1i - 1 with the color A_iA\_i.

In order to confirm whether the operations are correctly performed, JOI-kun wants to know in advance the colors of the stones after all the operations are performed.

Given information of the go stones, write a program which determines the colors of the stones after the N operations are performed.

입력

Read the following data from the standard input.

NN

A_1A\_1

A_2A\_2

⋮\vdots

A_NA\_N

출력

Write NN lines to the standard output. The ii-th line (1≤i≤N1 ≤ i ≤ N) should contain the color of Stone ii after the NN operations are performed.

제한

  • 1≤N≤200,0001 ≤ N ≤ 200\\,000.
  • 1≤A_i≤1091 ≤ A\_i ≤ 10^9 (1≤i≤N1 ≤ i ≤ N).
  • Given values are all integers.

예제2

  1. 예제 1

    입력
    6
    1
    2
    1
    2
    3
    2
    
    예상 출력
    1
    1
    1
    2
    2
    2
    
  2. 예제 2

    입력
    10
    1
    1
    2
    2
    1
    2
    2
    1
    1
    2
    
    예상 출력
    1
    1
    1
    1
    1
    1
    1
    1
    1
    2