#P8203. [传智杯 #4 决赛] DDOSvoid 的馈赠

    ID: 9271 远端评测题 4000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>O2优化虚树AC 自动机根号分治传智杯

[传智杯 #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 nn strings s1,s2,,sns_1, s_2, \dots, s_n as a souvenir. In this problem, we call these nn strings "template strings".

Xiao Zhi already has mm strings t1,t2,tmt_1, t_2, \dots t_m. In this problem, we call these mm strings "query strings".

DDOSvoid's gift is not unconditional. He has qq questions. Each question gives two parameters x,yx, y and asks Xiao Zhi: how many template strings sis_i satisfy that sis_i is both a substring of txt_x and a substring of tyt_y?

Only if Xiao Zhi answers these qq questions correctly can he receive DDOSvoid's gift. Please help Xiao Zhi answer DDOSvoid's questions.

We say a string tt is a substring of ss if and only if, after deleting some (possibly 00) consecutive characters from the beginning of ss and some (possibly 00) consecutive characters from the end of ss, the remaining string is exactly tt. 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 nn, the number of query strings mm, and the number of queries qq.
The next nn lines each contain one string, representing the template strings s1,s2,sns_1, s_2, \dots s_n in order.
The next mm lines each contain one string, representing the query strings t1,t2,tmt_1, t_2, \dots t_m in order.
The next qq lines each contain two integers x,yx, y, 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 1n,m,q,si,ti1051\leq n,m,q,|s_i|,|t_i| \leq 10^5, and the total length of template strings and the total length of query strings are both at most 10510^5, i.e., $\sum\limits_{i = 1}^n |s_i|,\sum\limits_{i = 1}^m|t_i| \leq 10^5$, where x|x| denotes the length of string xx. It is guaranteed that the input strings contain only lowercase letters, and 1xym1 \leq x\neq y \leq m.

Hint

Please pay attention to the impact of constant factors on program efficiency.

Translated by ChatGPT 5