Lyndon Substring
Time limit3sMemory limit256 MB
For each query (i, j), find the length of the longest Lyndon substring of the concatenation s_i s_j, given n strings and m queries.
- Level
Hard9 of 10
- Topics
- String, String matching, Greedy
- Solved
- No attempts yet
Problem
A string is a Lyndon word if is lexicographically smaller than any of its cyclic rotations.
The longest Lyndon substring of a string is the longest substring of that is a Lyndon word.
Chiaki has strings . She has some queries. For a pair , find the length of the longest Lyndon substring of the string .
Input
There are multiple test cases. The first line of input contains an integer , the number of test cases. For each test case:
The first line contains two integers and (), the number of strings and the number of queries.
Each of the next lines contains a nonempty string () consisting of lowercase English letters.
Each of the next lines contains two integers and () denoting a query.
It is guaranteed that in one test case the sum of all does not exceed , and that in all cases the sum of all does not exceed .
It is guaranteed that neither the sum of all nor the sum of all exceeds .
Output
For each query, output an integer denoting the answer.