#P7361. 「JZOI-1」拜神
「JZOI-1」拜神
Description
There are a total of gods that Xiao Xi wants to worship. Xiao Xi’s belief for each god can be represented by a lowercase letter. Putting them together forms a string indexed starting from .
Xiao Xi needs prayer words to worship the gods. A prayer word is defined as a non-empty contiguous substring of , and its length is the length of this substring. Since worshipping only requires Xiao Xi to be serious enough, a prayer word is considered valid as long as it appears at least twice.
Note: as long as the starting positions of the two occurrences are different, it is fine even if the two substrings overlap.
However, because her parents are also present, Xiao Xi’s prayer words may sometimes be interrupted, so only the string within the interval (i.e., ) is valid. To be prepared, Xiao Xi will carefully prepare for all possible situations.
He will give queries. In each query, are given, and you need to ask for the length of the longest valid prayer word within the interval .
Input Format
The first line contains two positive integers .
The second line contains a string consisting of lowercase letters.
The next lines each contain two numbers .
Output Format
Output lines. Each line outputs a non-negative integer, representing the length of the longest valid prayer word. If there is no valid prayer word, output .
10 5
cdabababdc
3 7
2 8
5 10
6 10
1 4
3
4
2
1
0
Hint
Sample Explanation:
For the first query: the string in the interval is , where the substring appears twice, with length .
For the second query: the string in the interval is , where the substring appears twice, with length .
For the third query: the string in the interval is , where the substring appears twice, with length .
For the fourth query: the string in the interval is , where the substring appears twice, with length .
For the fifth query: the string in the interval is , and no substring appears at least twice, so the answer is .
Constraints:
For of the data, .
For of the data, .
For of the data, .
For of the data, .
For of the data, .
For another of the data, all characters are the same.
For of the data, and .
Translated by ChatGPT 5
京公网安备 11011102002149号