#P5108. 仰望半月的夜空

仰望半月的夜空

Description

In the half-moon night sky, how many people’s feelings for each other are carried.

Xiyue knows that these feelings will gather into a string SS (n=Sn = |S|).

Because the feelings are gathered in a way that is too complex, Xiyue hopes to refine all of them.

We define YS(i)Y_S(i) as follows: for the string SS, among all substrings of length ii, take the lexicographically smallest one; if there are multiple, take the one with the smallest left endpoint. Then YS(i)Y_S(i) is the value of that left endpoint.

For example, for S="baa"S = \texttt{"baa"}, YS(1)=2Y_S(1) = 2, YS(2)=2Y_S(2) = 2, YS(3)=1Y_S(3) = 1.

Xiyue will tell you the string SS. You only need to tell Xiyue YS(i)Y_S(i) (1in1 \le i \le n).

Input Format

The first line contains two parameters: σ{10,26,107}\sigma \in \{10, 26, 10^7\} and nn.

If σ=26\sigma = 26, then the second line is a lowercase letter string SS of length nn.

Otherwise, the second line contains nn integers in [0,σ][0, \sigma].

Output Format

Output one line. The ii-th number表示 the value of YS(i)Y_S(i).

26 11
remoonqaqac
8 10 8 8 2 2 2 2 2 2 1
26 11
txdydkwqaqa

9 9 9 5 5 5 5 3 3 1 1
10000000 17
9 9 8 2 4 4 3 5 3 1 9 2 6 0 8 1 7
14 14 14 14 10 10 10 10 4 4 4 4 4 4 3 2 1

Hint

The Constraints chart is missing QAQ.

The maximum range is 1n3×1051 \le n \le 3 \times {10}^5.

Translated by ChatGPT 5