luogu#P5112. FZOUTSY
FZOUTSY
Problem Description
Original Meaning
cdm1020 is a shut-in. His favorite thing in daily life is chatting (and copying) in group chats.
He took the chat logs from a group he recently chatted in, and used some mysterious compression algorithm to compress these chat logs into a string of length . Because he is a chuunibyou-style fan, this string contains only kinds of characters: . Because of his obsession with suffix data structures, he is only interested in the suffixes of this string. He defines the index of a suffix to be if and only if the interval of the string it represents is .
cdm1020 defines a pair of suffixes to be “-level copying” if and only if the length of the longest common prefix of suffix and suffix is at least . In other words, a pair of -level copying suffixes is also -level copying.
Now he wants to ask: among the suffixes with indices in , how many pairs of suffixes are -level copying.
One-Sentence Meaning
Given a string of length over the alphabet and a query parameter , for multiple queries , find among the suffixes with indices in how many pairs of suffixes have LCP (longest common prefix) length at least .
A suffix has index if and only if it represents the characters in the interval .
Input Format
The first line contains three positive integers , representing the string length , the number of queries , and the query parameter .
The second line contains a string of length , which is the string you need to process.
The next lines each contain two positive integers , representing the query interval .
Output Format
Output lines, each containing a positive integer, representing the number of suffix pairs in the query interval whose LCP length is at least .
20 15 3
oouuoouuoouuoouuoouu
10 16
2 15
4 13
6 7
4 12
12 14
12 13
7 19
1 5
6 13
1 15
9 15
11 15
1 19
15 18
3
18
8
0
6
0
0
12
1
4
21
3
1
32
0
Hint
Constraints and Notes
For all testdata, , , , .
It is guaranteed that the input string contains only the lowercase letters .
Translated by ChatGPT 5