#P8203. [传智杯 #4 决赛] DDOSvoid 的馈赠
[传智杯 #4 决赛] DDOSvoid 的馈赠
Problem Description
Xiao Zhi is about to AK (All killed, meaning getting AC on all problems in this contest) the "Chuanzhi Cup" National College Student IT Skills Competition (Finals) and then leave. Before he leaves, DDOSvoid plans to give Xiao Zhi strings as a souvenir. In this problem, we call these strings "template strings".
Xiao Zhi already has strings . In this problem, we call these strings "query strings".
DDOSvoid's gift is not unconditional. He has questions. Each question gives two parameters and asks Xiao Zhi: how many template strings satisfy that is both a substring of and a substring of ?
Only if Xiao Zhi answers these questions correctly can he receive DDOSvoid's gift. Please help Xiao Zhi answer DDOSvoid's questions.
We say a string is a substring of if and only if, after deleting some (possibly ) consecutive characters from the beginning of and some (possibly ) consecutive characters from the end of , the remaining string is exactly . For example, ab is a substring of abc, but ac is not a substring of abc.
Input Format
The first line contains three integers, in order: the number of template strings , the number of query strings , and the number of queries .
The next lines each contain one string, representing the template strings in order.
The next lines each contain one string, representing the query strings in order.
The next lines each contain two integers , representing a query.
Output Format
For each query, output one line with one integer, the answer.
3 2 1
a
b
c
ab
bac
1 2
2
3 3 3
aaba
baba
aba
ababa
aabab
babaa
1 2
1 3
2 3
1
2
1
Hint
Constraints
For all testdata, it is guaranteed that , and the total length of template strings and the total length of query strings are both at most , i.e., $\sum\limits_{i = 1}^n |s_i|,\sum\limits_{i = 1}^m|t_i| \leq 10^5$, where denotes the length of string . It is guaranteed that the input strings contain only lowercase letters, and .
Hint
Please pay attention to the impact of constant factors on program efficiency.
Translated by ChatGPT 5