#P6629. [ZJOI2020] 字符串
[ZJOI2020] 字符串
Description
Bob likes strings.
Bob thinks that a string repeated twice is beautiful. For example, aa, sese, abcabc, baabaa, abababab are beautiful strings, while ab, aadead, sesese, abba are not. More specifically, if a string can be written as the concatenation of two identical strings, that is, there exists a string such that , then is beautiful.
Bob has a string of length . Now he wants to know: given a substring of , how many essentially different beautiful strings appear as substrings within this substring . If two strings are the same but occur at different positions, then they are not considered essentially different.
Bob has different queries in total. You need to compute the answers quickly.
Input Format
The first line contains two integers . The second line contains a string consisting only of lowercase letters a and b.
In the next lines, each line contains two integers , representing one query.
Output Format
Output lines, each with one integer representing the answer.
11 5
aabaabaaaab
1 11
1 6
7 10
5 5
3 8
5
2
2
0
2
Hint
Sample explanation 1:
In , the essentially different beautiful strings are aa, aaaa, abaaba, aabaab, baabaa.
Sample input/output 2 is provided in the attachment.
Constraints:
For the first of the testdata, .
For the first of the testdata, .
For the first of the testdata, .
For another of the testdata, it is guaranteed that the total number of beautiful substrings in does not exceed , where substrings at different positions are considered different.
For another of the testdata, .
For of the testdata, , . contains only lowercase letters a and b.
Translated by ChatGPT 5
京公网安备 11011102002149号