351 传统题

[ABC485C] 最近的异色邻居 (Different Neighbor)

时间限制
2000ms
内存限制
1024MiB
登顶 / 尝试
2/ 3
难度
2
    上传者 标签AtCoderABC 485普及-线性扫描前后缀

[ABC485C] 最近的异色邻居 (Different Neighbor)

Score : 300300 points

Problem Statement

There is one point at each of the coordinates 1,2,…,N1, 2, \ldots, N on a number line, and the point at coordinate ii is called point ii.

Each point has a color, and the color of point ii is CiC_i. Here, at least two distinct values appear in C1,C2,…,CNC_1, C_2, \ldots, C_N.

For each i=1,2,…,Ni = 1, 2, \ldots, N, find the distance from point ii to the nearest point whose color is different from that of point ii.

Constraints

  • 2≤N≤3×1052 \leq N \leq 3 \times 10^5

  • 1≤Ci≤N1 \leq C_i \leq N

  • At least two distinct values appear in C1,C2,…,CNC_1, C_2, \ldots, C_N.

  • All input values are integers.

Input

The input is given from Standard Input in the following format:

$N$
$C_1$ $C_2$ $\ldots$ $C_N$

Output

Print the answers for i=1,2,…,Ni = 1, 2, \ldots, N in this order, separated by spaces.

Sample Input 1

6
1 1 2 3 3 3

Sample Output 1

2 1 1 1 2 3

Among the points whose color is different from that of point 11, the nearest to point 11 is point 33, and its distance from point 11 is 22.

Among the points whose color is different from that of point 22, the nearest to point 22 is point 33, and its distance from point 22 is 11.

Among the points whose color is different from that of point 33, the nearest to point 33 are points 22 and 44, and their distance from point 33 is 11.

Among the points whose color is different from that of point 44, the nearest to point 44 is point 33, and its distance from point 44 is 11.

Among the points whose color is different from that of point 55, the nearest to point 55 is point 33, and its distance from point 55 is 22.

Among the points whose color is different from that of point 66, the nearest to point 66 is point 33, and its distance from point 66 is 33.

Thus, print 2,1,1,1,2,32, 1, 1, 1, 2, 3 in this order, separated by spaces.

Sample Input 2

7
4 2 3 3 3 4 4

Sample Output 2

1 1 1 2 1 1 2