logo AlgoBeat OnlineJudge
登录 注册

#213874. [CERC 2021] Repetitions

内存限制:512 MiB 时间限制:10000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Bob is an aspiring avant-garde writer. He disdains the use of spaces, punctuation, capital letters and the like; hence, his stories are nothing but long strings of lowercase letters of the English alphabet. Critics have also noted that his style is marked by a certain fondness for repetitions, in the sense that it sometimes happens that two instances of the same substring appear in his story twice in a row, without any other intervening characters.

Bob has submitted his latest masterpiece, a string which happens to be characters long, to different literary magazines in the hopes that at least one of them might be willing to publish it. The response was more favourable than he had dared to hope. The editors of all magazines have expressed willingness to publish some part (i.e. a substring) of his story, but on the condition that he identify the longest repetition (i.e. a shorter substring appearing twice in a row) within that part of the story. The editors intend to remove that part to prevent the story from being too boring. Now Bob needs your help to answer these queries from the editors.

Write a program that, given a string of letters, , answers queries of the form "given and , how long is the longest string for which appears as a substring of , and where does the leftmost such occurrence begin?"

输入格式

The first line contains two integers, and . The second line contains the string , which is characters long; all these characters are lowercase letters of the English alphabet. The remaining lines describe the queries; the -th of these lines contains the integers and , separated by a space.

输出格式

Output lines; the -th of these lines must contain two space-separated integers and . should be the length of the longest string for which appears as a substring in , and should be the index at which the leftmost repetition of this length begins, i.e. the smallest integer such that , and . (If , then by definition.)

样例

样例输入 1

10 4
cabaabaaca
4 8
1 9
5 9
8 10

样例输出 1

1 4
3 2
1 7
0 8

数据范围与提示

Comment

The four queries in the above example refer to the substrings \underline is only supported in math mode\textbf{\underline{a}abaa}, \underline is only supported in math mode\textbf{c\underline{aba}abaac}, \underline is only supported in math mode\textbf{ab\underline{a}ac}, and ; the part shown in bold is the substring referred to by the result of that query (a substring of length , beginning at index ). In the last query there is no repetition, so .

Input limits

  • for each