#abc213f. F - Common Prefixes

F - Common Prefixes

Score : 500500 points

问题描述

令两个字符串 XXYY 之间的 相似度 f(X,Y)f(X,Y) 为它们最长公共前缀的长度。
例如,字符串 abcaxbc 之间的相似度为 11,而字符串 aaaaaaa 之间的相似度为 33

现在给定一个长度为 NN 的字符串 SS。令 SiS_i 表示从 SS 的第 ii 个字符开始的后缀。对于每个 k=1,,Nk=1,\ldots,N,计算并求出 f(Sk,S1)+f(Sk,S2)++f(Sk,SN)f(S_k,S_1)+f(S_k,S_2)+\ldots+f(S_k,S_N) 的值。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Let the similarity f(X,Y)f(X,Y) between two strings XX and YY be the length of their longest common prefix.
For example, the similarity between abc and axbc is 11, and the similarity between aaa and aaaa is 33.

You are given a string SS of length NN. Let SiS_i be the suffix of SS beginning with the ii-th character of SS. For each k=1,,Nk=1,\ldots,N, find f(Sk,S1)+f(Sk,S2)++f(Sk,SN)f(S_k,S_1)+f(S_k,S_2)+\ldots+f(S_k,S_N).

Constraints

  • 1N1061 \leq N \leq 10^6
  • SS is a string of length NN consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

NN

SS

Output

Print NN lines.

The ii-th line should contain the answer for k=ik=i.

Sample Input 1

3
abb

Sample Output 1

3
3
2

S1S_1 is abb, S2S_2 is bb, and S3S_3 is b.

  • For k=1k=1: f(S1,S1)+f(S1,S2)+f(S1,S3)=3+0+0=3f(S_1,S_1)+f(S_1,S_2)+f(S_1,S_3)=3+0+0=3.
  • For k=2k=2: f(S2,S1)+f(S2,S2)+f(S2,S3)=0+2+1=3f(S_2,S_1)+f(S_2,S_2)+f(S_2,S_3)=0+2+1=3.
  • For k=3k=3: f(S3,S1)+f(S3,S2)+f(S3,S3)=0+1+1=2f(S_3,S_1)+f(S_3,S_2)+f(S_3,S_3)=0+1+1=2.

Sample Input 2

11
mississippi

Sample Output 2

11
16
14
12
13
11
9
7
4
3
4

update @ 2024/3/10 09:30:07

}