Suffix Automaton
Time limit6sMemory limit1024 MB
Given a string S, find the k-th distinct substring when all substrings are sorted by length, then lexicographically, and print its first occurrence positions.
- Level
Hard8 of 10
- Topics
- String, String matching, Sorting
- Solved
- No attempts yet
Problem
JB is the National Olympiad Tutor of Suffix Automaton. Today he comes up with the following problem.
Suppose you have a string . Write down all the distinct substrings of . Sort them by length in increasing order. For two strings of the same length, the one that is lexicographically smaller comes first. The result is a sorted sequence of strings.
JB has questions. For each question, he gives you an integer , and you tell him the -th string in .
To simplify the problem, you only need to output the left and right positions in of the first occurrence of that string.
Input
The first line contains one string (), containing only lowercase letters.
The second line contains one integer ().
Each of the following lines contains one integer ().
Output
For each question, print two integers , the left and right positions in of the first occurrence of the answer string. If is greater than the length of , print "-1 -1".