Baby's First Suffix Array Problem
Time limit14sMemory limit512 MB
For each query substring x = s[l..r], count the suffixes of x that are lexicographically no larger than the suffix s[k..r].
- Level
Hard8 of 10
- Topics
- String, String matching, Divide and conquer
- Solved
- No attempts yet
Problem
A suffix array for string of length is a permutation of integers from to such that is the list of non-empty suffixes of sorted in lexicographical order. The rank table for suffixes of is a permutation of integers from to such that .
Kotori has a string . She would like to ask queries. In the -th query, a substring of is given, and Kotori would like to know the rank of the suffix of .
means the substring of that starts at the -th position and ends at the -th position, both inclusive.
Input
There are multiple test cases. The first line of the input contains an integer , the number of test cases. Each test case is as follows.
The first line contains two integers and (), the length of the string and the number of queries.
The second line contains a string of length consisting only of lowercase English letters.
Each of the next lines contains three integers , , and (, ), describing a query.
The sum of over all test cases and the sum of over all test cases do not exceed .
Output
For each query, output one line containing one integer, the answer.