#15831. [ICPC 2020 Nanjing R] Baby's First Suffix Array Problem
[ICPC 2020 Nanjing R] Baby's First Suffix Array Problem
[ICPC 2020 Nanjing R] Baby's First Suffix Array Problem
题目描述
A suffix array for string $s$ of length $n$ is a permutation $sa$ of integers from $1$ to $n$ such that $s[sa_1.. n], s[sa_2..n], \dots, s[sa_n..n]$ is the list of non-empty suffixes of $s$ sorted in lexicographical order. The rank table for suffixex of $s$ is a permutation $rank$ of integers from $1$ to $n$ such that $rank_{sa_i} = i$.Kotori has a string . She would like to ask queries. And in the -th query, a substring of is given, Kotori would like to know the rank of suffix of .
Note means the substring of which starts from the -th position and ends at the -th position, both inclusive.
输入格式
There are multiple test cases. The first line of the input contains an integer $T$ indicating the number of test cases. For each test case: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 () denoting a query.
It is guaranteed that neither the sum of or the sum of of all test cases will exceed .
输出格式
For each query output one line containing one integer denoting the answer.2
10 4
baaabbabba
2 8 3
1 1 1
2 3 2
2 5 4
20 3
cccbccbadaacbbbcccab
14 17 16
3 20 17
17 20 18
2
1
2
3
4
15
3