F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

K-th occurrence

Time Limit: 3000/3000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 3712    Accepted Submission(s): 1084


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 $S_lS_{l+1}...S_r$ in S.
 

Input
The first line contains an integer $T(1 \leq T \leq 20)$, denoting the number of test cases.

The first line of each test case contains two integer $N(1 \leq N \leq 10^5), Q(1 \leq Q \leq 10^5)$, 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 \leq l \leq r \leq N)$ and $k(1 \leq k \leq N)$, denoting a query.

There are at most $5$ testcases which $N$ is greater than $10^3$.
 

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
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-17 03:43:18, Gzip enabled