#P5829. 【模板】失配树
【模板】失配树
Problem Description
Given a string , define its -prefix as the substring , and its -suffix as the substring , where .
Define as the set of strings that satisfy for , . Each element in is called a of the string .
There are queries. Each query gives . Find the length of the longest common of the -prefix and the -prefix of .
Input Format
The first line contains a string .
The second line contains an integer .
The next lines each contain two integers .
Output Format
For each query, output one integer per line, representing the answer. If there is no common , output .
aaaabbabbaa
5
2 4
7 10
3 4
1 2
4 11
1
1
2
0
2
zzaaccaazzccaacczz
3
2 18
10 18
3 5
1
2
0
Hint
Explanation for Sample 2:
For the first query, the -prefix and the -prefix are zz and zzaaccaazzccaacczz. Since zz has only one , namely z, the length of the longest common is .
For of the testdata, all characters in are the same.
For of the testdata, , , and .
Constraints.
Translated by ChatGPT 5