#P4094. [HEOI2016/TJOI2016] 字符串
[HEOI2016/TJOI2016] 字符串
Description
On Jiayuan’s birthday, her friends bought her a birthday gift from an online store. The gift is placed in a magic box. On the outside of the box there is a string of length , and questions. Jiayuan must answer these questions correctly to open the box and get the gift, get promoted and receive a raise, become the CEO, marry a rich and handsome man, and reach the pinnacle of life.
Each question has four parameters . Among all substrings of , what is the maximum possible length of the longest common prefix with ? Jiayuan is not good at such problems, so she asks you for help. How would you help her?
Input Format
The first line contains two positive integers , denoting the length of the string and the number of queries.
The next line contains a string of length . Then there are lines, each containing four integers , representing a query asking for the maximum length of the longest common prefix between any substring of and .
Output Format
For each query, output the answer.
5 5
aaaaa
1 1 1 5
1 5 1 1
2 3 2 3
2 4 2 3
2 3 2 4
1
1
2
2
2
Hint
For of the testdata, .
For of the testdata, , and the string contains only a, b.
For of the testdata, , the string contains only lowercase English letters, , , and .
Translated by ChatGPT 5
京公网安备 11011102002149号