SUBLEX  Lexicographical Substring Search
Little Daniel loves to play with strings! He always finds different ways to have fun with strings! Knowing that, his friend Kinan decided to test his skills so he gave him a string S and asked him Q questions of the form:
If all distinct substrings of string S were sorted lexicographically, which one will be the Kth smallest?
After knowing the huge number of questions Kinan will ask, Daniel figured out that he can't do this alone. Daniel, of course, knows your exceptional programming skills, so he asked you to write him a program which given S will answer Kinan's questions.
Example:
S = "aaa" (without quotes)
substrings of S are "a" , "a" , "a" , "aa" , "aa" , "aaa". The sorted list of substrings will be:
"a", "aa", "aaa".
Input
In the first line there is Kinan's string S (with length no more than 90000 characters). It contains only small letters of English alphabet. The second line contains a single integer Q (Q <= 500) , the number of questions Daniel will be asked. In the next Q lines a single integer K is given (0 < K < 2^31).
Output
Output consists of Q lines, the ith contains a string which is the answer to the ith asked question.
Example
Input:
aaa
2
2
3
Output: aa
aaa
Edited: Some input file contains garbage at the end. Do not process them.
hide comments
rawfisher:
20170925 16:40:32
I got AC if I ignore the case that k >= (distinct substrings)... 

rohit659:
20170907 14:05:16
My 150th :)


Thotsaphon Thanatipanonda:
20170604 10:50:13
output should be starting position and length of result string, not the whole result string. 

maxwei_wzj:
20170402 05:15:26
Finally get AC with SAM!!! 

sdfzyhx:
20170330 12:25:33
SA can be O(nlogn+qlogq) 

cydiater:
20170120 14:09:09
SAM is best 

Chowdhury Osman:
20161216 23:20:27
Suffice array with O(n * (logn)^2) is enough. 

kiwi1995:
20161216 12:13:56
suffix tree:D 

flaze:
20160801 17:42:57
well...I got WA for lots of times when supposing there is possibility that the K would be larger than the#(distinct substrings)...But I got AC supposing it doesn't exist.....It is strange... 

sxie12:
20160323 21:23:21
Suffix array nlog^2n with optimization, LCP, and binary search passed. 
Added by:  Damir Ferizovic 
Date:  20100902 
Time limit:  0.149s0.299s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: NODEJS OBJC VB.NET 
Resource:  Own Problem 