CF1721E.Prefix Function Queries
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a string s , consisting of lowercase Latin letters.
You are asked q queries about it: given another string t , consisting of lowercase Latin letters, perform the following steps:
- concatenate s and t ;
- calculate the prefix function of the resulting string s+t ;
- print the values of the prefix function on positions ∣s∣+1,∣s∣+2,…,∣s∣+∣t∣ ( ∣s∣ and ∣t∣ denote the lengths of strings s and t , respectively);
- revert the string back to s .
The prefix function of a string a is a sequence p1,p2,…,p∣a∣ , where pi is the maximum value of k such that k<i and a[1..k]=a[i−k+1..i] ( a[l..r] denotes a contiguous substring of a string a from a position l to a position r , inclusive). In other words, it's the longest proper prefix of the string a[1..i] that is equal to its suffix of the same length.
给你一个由小写拉丁字母组成的字符串 s 。
向您提出有关它的 q 个问题:给您另一个由小写拉丁字母组成的字符串 t ,请执行以下步骤:
- 连接 s 和 t ;
- 计算得到的字符串 s+t 的前缀函数;
- 在位置 ∣s∣+1,∣s∣+2,…,∣s∣+∣t∣ 上打印前缀函数值( ∣s∣ 和 ∣t∣ 分别表示字符串 s 和 t 的长度);
- 将字符串还原为 s 。
字符串 a 的前缀函数是一个序列 p1,p2,…,p∣a∣ ,其中 pi 是 k 的最大值,而 k < i 和 a[1..k]=a[i−k+1..i] 是 k 的最大值。 a[l..r] 表示字符串 a 从位置 l 到位置 r (含)的连续子串)。换句话说,它是字符串 a[1..i] 的最长适当前缀,等于其相同长度的后缀。
输入格式
The first line contains a non-empty string s ( 1≤∣s∣≤106 ), consisting of lowercase Latin letters.
The second line contains a single integer q ( 1≤q≤105 ) — the number of queries.
Each of the next q lines contains a query: a non-empty string t ( 1≤∣t∣≤10 ), consisting of lowercase Latin letters.
输入
第一行包含一个非空字符串 s ( 1≤∣s∣≤106 ),由小写拉丁字母组成。
第二行包含一个整数 q ( 1≤q≤105 ) - 查询次数。
接下来的每行 q 都包含一个查询:一个由小写拉丁字母组成的非空字符串 t ( 1≤∣t∣≤10 )。
输出格式
For each query, print the values of the prefix function of a string s+t on positions ∣s∣+1,∣s∣+2,…,∣s∣+∣t∣ .
输出
针对每个查询,打印位置 ∣s∣+1,∣s∣+2,…,∣s∣+∣t∣ 上字符串 s+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