CF1721E.Prefix Function Queries

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a string ss , consisting of lowercase Latin letters.

You are asked qq queries about it: given another string tt , consisting of lowercase Latin letters, perform the following steps:

  1. concatenate ss and tt ;
  2. calculate the prefix function of the resulting string s+ts+t ;
  3. print the values of the prefix function on positions s+1,s+2,,s+t|s|+1, |s|+2, \dots, |s|+|t| ( s|s| and t|t| denote the lengths of strings ss and tt , respectively);
  4. revert the string back to ss .

The prefix function of a string aa is a sequence p1,p2,,pap_1, p_2, \dots, p_{|a|} , where pip_i is the maximum value of kk such that k<ik < i and a[1..k]=a[ik+1..i]a[1..k]=a[i-k+1..i] ( a[l..r]a[l..r] denotes a contiguous substring of a string aa from a position ll to a position rr , inclusive). In other words, it's the longest proper prefix of the string a[1..i]a[1..i] that is equal to its suffix of the same length.
给你一个由小写拉丁字母组成的字符串 ss

向您提出有关它的 qq 个问题:给您另一个由小写拉丁字母组成的字符串 tt ,请执行以下步骤:

  1. 连接 sstt
  2. 计算得到的字符串 s+ts+t 的前缀函数;
  3. 在位置 s+1,s+2,,s+t|s|+1, |s|+2, \dots, |s|+|t| 上打印前缀函数值( s|s|t|t| 分别表示字符串 sstt 的长度);
  4. 将字符串还原为 ss

字符串 aa 的前缀函数是一个序列 p1,p2,,pap_1, p_2, \dots, p_{|a|} ,其中 pip_ikk 的最大值,而 k < i 和 a[1..k]=a[ik+1..i]a[1..k]=a[i-k+1..i]kk 的最大值。 a[l..r]a[l..r] 表示字符串 aa 从位置 ll 到位置 rr (含)的连续子串)。换句话说,它是字符串 a[1..i]a[1..i] 的最长适当前缀,等于其相同长度的后缀。

输入格式

The first line contains a non-empty string ss ( 1s1061 \le |s| \le 10^6 ), consisting of lowercase Latin letters.

The second line contains a single integer qq ( 1q1051 \le q \le 10^5 ) — the number of queries.

Each of the next qq lines contains a query: a non-empty string tt ( 1t101 \le |t| \le 10 ), consisting of lowercase Latin letters.
输入

第一行包含一个非空字符串 ss ( 1s1061 \le |s| \le 10^6 ),由小写拉丁字母组成。

第二行包含一个整数 qq ( 1q1051 \le q \le 10^5 ) - 查询次数。

接下来的每行 qq 都包含一个查询:一个由小写拉丁字母组成的非空字符串 tt ( 1t101 \le |t| \le 10 )。

输出格式

For each query, print the values of the prefix function of a string s+ts+t on positions s+1,s+2,,s+t|s|+1, |s|+2, \dots, |s|+|t| .
输出

针对每个查询,打印位置 s+1,s+2,,s+t|s|+1, |s|+2, \dots, |s|+|t| 上字符串 s+ts+t 的前缀函数值。

输入输出样例

  • 输入#1

    aba
    6
    caba
    aba
    bababa
    aaaa
    b
    forces

    输出#1

    0 1 2 3 
    1 2 3 
    2 3 4 5 6 7 
    1 1 1 1 
    2 
    0 0 0 0 0 0
  • 输入#2

    aacba
    4
    aaca
    cbbb
    aab
    ccaca

    输出#2

    2 2 3 1 
    0 0 0 0 
    2 2 0 
    0 0 1 0 1
首页