Listening Test Practice
Time limit3sMemory limit1024 MB
For each query, count the substrings of S whose longest common prefix with T[i..j] is exactly k characters.
- Level
Hard8 of 10
- Topics
- String matching, Sorting, Binary search
- Solved
- No attempts yet
Problem
The importance of algorithms has become widely known, so more people now want to join SUAPC. Following this trend, SUAPC added a listening test section. Rao can code but is weak at listening, so he plans to practice the listening test with past exam problems.
Rao's vocabulary list is a string of length , and his past exam collection is a string of length . Rao must solve practice problems of the following form. When two strings have the same first characters, they are said to be -similar. Two strings are not -similar if one of them has length less than , or if they match in their first or more characters.
- : Output the number of substrings of that are -similar to the substring of .
A substring is a contiguous part of a string. A substring cannot be empty.
Input
The first line contains , , and separated by spaces, where is the length of the vocabulary list, is the length of the exam collection, and is the number of practice problems. ()
The second line contains the string of length , made of lowercase English letters.
The third line contains the string of length , made of lowercase English letters.
The next lines each give a practice problem in the form i j k. (, )
Output
Print the answer to each practice problem on its own line, in order.