luogu#P5108. 仰望半月的夜空

仰望半月的夜空

Background

“You will soon meet a girl you like. Listen carefully, you must protect her well.”

This was the advice that Father gave to Yuichi Ronzaki.

Father could hardly be called a qualified father.

But it was exactly such a father who connected Yuichi Ronzaki and Rika Akiba.

Rika Akiba is a girl who is clearly a tsundere, yet someone you cannot help but protect.

At the same time, she is also a girl who stays strong for memories, and for innocent love.

Do you see Sayoko’s shadow in her, Doctor Goro Natsume?

Do you see your past self in him, Doctor Goro Natsume?

Maybe illness cuts off the connection between people, but the traces that once existed will surely turn into beautiful memories and be passed on.

May you be happy.

Problem 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