#P14729. [ICPC 2022 Seoul R] Longest Substring

    ID: 16557 远端评测题 5000ms 2048MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2022后缀自动机 SAMICPC根号分治启发式合并首尔

[ICPC 2022 Seoul R] Longest Substring

题目描述

For a string SS of length n1n \geq 1 and a positive integer kk (1kn1 \leq k \leq n), a non-empty substring of SS is called a kk-substring if the substring appears exactly kk times. Such kk occurrences are not necessarily disjoint, i.e., are possibly overlapping. For example, if S=ababaS = \text{ababa}, the kk-substrings of SS for every k=1,...,5k = 1, ..., 5 are as follows:

  • There are four 1-substrings in SS, abab\text{abab}, ababa\text{ababa}, bab\text{bab}, and baba\text{baba} because these substrings appear exactly once in SS. Note that aba\text{aba} is not a 1-substring because it appears twice.
  • There are four 2-substrings in SS, ab\text{ab}, aba\text{aba}, b\text{b}, and ba\text{ba}. The substring ab\text{ab} appears exactly twice without overlapping. Two occurrences of the substring aba\text{aba} are overlapped at a common character a\text{a}, but it does not appear three times or more.
  • There is only one 3-substring in SS, a\text{a}.
  • Neither 4-substrings nor 5-substrings exist in SS.

For a kk-substring TT of SS, let d(T)d(T) be the maximum number of the disjoint occurrences of TT in SS. For example, a 2-substring T=abT = \text{ab} can be selected twice without overlapping, that is, the maximum number of the disjoint occurrences is two, so d(T)=2d(T) = 2. For a 2-substring T=abaT = \text{aba}, it cannot be selected twice without overlapping, so d(T)=1d(T) = 1. For a 3-substring T=aT = \text{a}, it can be selected three times without overlapping, which is the maximum, so d(T)=3d(T) = 3.

Let f(k)f(k) be the length of the longest one among all kk-substring TT with the largest d(T)d(T) for 1kn1 \leq k \leq n. For example, f(k)f(k) for S=ababaS = \text{ababa} and k=1,...,5k = 1, ..., 5 is as follows:

  • For k=1k = 1, all 1-substrings TT can be selected only once without overlapping, so d(T)=1d(T) = 1. Thus, the longest one among all 1-substrings with d(T)=1d(T) = 1 is ababa\text{ababa}, so f(1)=5f(1) = 5.
  • For k=2k = 2, d(T)=1d(T) = 1 for T=abaT = \text{aba}, but d(T)=2d(T) = 2 for the other 2-substrings T=abT = \text{ab}, b\text{b}, ba\text{ba}. Among 2-substrings with d(T)=2d(T) = 2, ab\text{ab} and ba\text{ba} are the longest ones, so f(2)=2f(2) = 2.
  • For k=3k = 3, f(3)=1f(3) = 1 because there is only one 3-substring a\text{a}.
  • For k=4,5k = 4, 5, there are no kk-substrings, so f(4)=0f(4) = 0 and f(5)=0f(5) = 0.

Given a string SS of length nn, write a program to output nn values of f(k)f(k) from k=1k = 1 to k=nk = n. For the above example, the output should be 5 2 1 0 05\ 2\ 1\ 0\ 0.

输入格式

Your program is to read from standard input. The input starts with a line containing the string SS consisting of nn (1n50,0001 \leq n \leq 50,000) lowercase alphabets.

输出格式

Your program is to write to standard output. Print exactly one line. The line should contain exactly nn non-negative integers, separated by a space, that represent f(k)f(k) from k=1k = 1 to k=nk = n in order, that is, f(1) f(2) ... f(n)f(1)\ f(2)\ ...\ f(n). Note that f(k)f(k) should be zero if there is no kk-substring for some kk.

ababa
5 2 1 0 0
aaaaaaaa
8 7 6 5 4 3 2 1