CF1721E.Prefix Function Queries
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
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<i 且 a[1..k]=a[i−k+1..i] 的最大 k 值(a[l..r] 表示字符串 a 中从位置 l 到位置 r(含端点)的连续子串)。换言之,pi 是字符串 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+t 在位置 ∣s∣+1,∣s∣+2,…,∣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
输入解题思路,AI测评打分。不知道怎么写?