Problem Description
You are given a string S consisting of only lowercase english letters and some queries.
For each query (l,r,k), please output the starting position of the k-th occurence of the substring SlSl+1...Sr in S.
Input
The first line contains an integer T(1≤T≤20), denoting the number of test cases.
The first line of each test case contains two integer N(1≤N≤105),Q(1≤Q≤105), denoting the length of S and the number of queries.
The second line of each test case contains a string S(|S|=N) consisting of only lowercase english letters.
Then Q lines follow, each line contains three integer l,r(1≤l≤r≤N) and k(1≤k≤N), denoting a query.
There are at most 5 testcases which N is greater than 103.
Output
For each query, output the starting position of the k-th occurence of the given substring.
If such position don't exists, output −1 instead.
Sample Input
2 12 6 aaabaabaaaab 3 3 4 2 3 2 7 8 3 3 4 2 1 4 2 8 12 1 1 1 a 1 1 1
Sample Output
5 2 -1 6 9 8 1
题目大意:给出一个字符串,q次询问,每次询问l, r, k.就是l~r这段区间的字串在文本串中出现第k次的位置。
解题思路:后缀数组求解。在height数组上找到一段大于所要查找的字符串长度的区间。所找到的这个区间在sa数组中对应区间做一个主席树查询区间第k大就可以了。比较麻烦的是在用RMQ找区间左右边界的情况