#P15725. [JAG 2023 Summer Camp #3] LCP Queries
[JAG 2023 Summer Camp #3] LCP Queries
题目描述
A string is called a prefix of a string if can be obtained by repeating the removal of the last letter of zero or more times. For example, “abac”, “aba”, “ab”, “a”, and an empty string are the prefixes of “abac”.
For two strings and , let be the length of the longest common prefix of and . For example, because the longest common prefix of these two strings is “abac”. Note that is always defined for any strings and because at least an empty string is one of their common prefixes.
You are given strings and strings of lowercase English letters. Then, you are given queries. In each query you are given an integer sequence . Let be the concatenation of . Your task is to calculate .
输入格式
The input consists of a single test case of the following format.
$$\begin{aligned} &n \\ &s_1 \\ &\vdots \\ &s_n \\ &m \\ &t_1 \\ &\vdots \\ &t_m \\ &q \\ &\text{Query}_1 \\ &\vdots \\ &\text{Query}_q \end{aligned} $$The first line consists of an integer . Each of the next lines consists of a non-empty string of lowercase English letters. The next line consists of an integer . Each of the next lines consists of a non-empty string of lowercase English letters.
The next line consists of an integer . Then queries are given in order. Each of the queries is given in a single line in the following format.
is a positive integer which represents the length of the integer sequence of this query. Each is an integer between and , inclusive.
You can assume that , and . The sum of lengths of does not exceed . Similarly, the sum of lengths of does not exceed . The sum of over all queries does not exceed .
输出格式
Output lines. The -th line should be the answer to the -th query.
5
abcde
aaa
a
ab
bcd
5
a
bc
de
aaaa
b
5
1 1
3 1 2 3
2 2 3
5 5 4 3 2 1
3 3 3 3
4
9
3
1
0