logo AlgoBeat OnlineJudge
登录 注册

#208778. [JOI 2023 Final] 石子排列 2 / Stone Arranging 2

内存限制:1024 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

JOI-kun has go stones. The stones are numbered from to . The color of each stone is an integer between and , inclusive. In the beginning, the color of Stone () is .

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

  1. JOI-kun will put Stone on the immediate right of Stone . However, when , JOI-kun will put Stone 1 on the table.
  2. If there is a stone among Stones whose current color is the same as Stone , let be the maximum index of such stones, and JOI-kun will paint all of Stones with the color .

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 operations are performed.

输入格式

Read the following data from the standard input.





输出格式

Write lines to the standard output. The -th line () should contain the color of Stone after the operations are performed.

样例

样例输入 1

6
1
2
1
2
3
2

样例输出 1

1
1
1
2
2
2

样例输入 2

10
1
1
2
2
1
2
2
1
1
2

样例输出 2

1
1
1
1
1
1
1
1
1
2

数据范围与提示

Samples

Sample 1

The operations are performed as in the following table.

Finally, the colors of Stones 1, 2, 3, 4, 5, 6 will be 1, 1, 1, 2, 2, 2, respectively.

This sample input satisfies the constraints of Subtasks 1, 3.

Sample 2

This sample input satisfies the constraints of all the subtasks.

Constraints

  • .
  • ().
  • Given values are all integers.

Subtasks

  1. (25 points) .
  2. (35 points) ().
  3. (40 points) No additional constraints.