#P9349. [JOI 2023 Final] Stone Arranging 2
[JOI 2023 Final] Stone Arranging 2
题目描述
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:
- JOI-kun will put Stone on the immediate right of Stone . However, when , JOI-kun will put Stone 1 on the table.
- 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.
题目大意
JOI 君有 枚棋子,棋子从 到 编号。每个棋子的颜色是介于 和 之间的整数,包括 和 。一开始,第 ()枚棋子的颜色是 。
接下来,JOI 君将执行 步操作。他将把棋子放在桌子上排成一行。第 ()步操作如下:
- JOI 君会将第 枚棋子放在第 枚棋子的紧邻的右侧。 特别地,当 时,JOI 君会直接将第 1 枚棋子放在桌子上。
- 如果前 枚棋子中有至少一枚棋子当前的颜色与棋子 相同,设 为这些棋子的编号的最大值,那么 JOI 君会把第 枚棋子的颜色都涂成 。
为了确认操作有没有正确完成,JOI 君想提前知道所有操作完成后棋子的颜色。
给定棋子的信息,编写一个程序,确定在执行 次操作后每枚棋子的颜色。
6
1
2
1
2
3
2
1
1
1
2
2
2
10
1
1
2
2
1
2
2
1
1
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
- (25 points) .
- (35 points) ().
- (40 points) No additional constraints.