[POI2012] OKR-A Horrible Poem

题意翻译

给出一个由小写英文字母组成的字符串 $S$,再给出 $q$ 个询问,要求回答 $S$ 某个子串的最短循环节。 如果字符串 $B$ 是字符串 $A$ 的循环节,那么 $A$ 可以由 $B$ 重复若干次得到。 --- 第一行一个正整数 $n\ (n\le 5\times 10^5)$,表示 $S$ 的长度。 第二行 $n$ 个小写英文字母,表示字符串 $S$。 第三行一个正整数 $q\ (q\le 2\times 10^6)$,表示询问次数。 下面 $q$ 行每行两个正整数 $a,b(1\le a\le b\le n)$,表示询问字符串 $S[a\cdots b]$ 的最短循环节长度。

题目描述

Bytie boy has to learn a fragment of a certain poem by heart. The poem, following the best lines of modern art, is a long string consisting of lowercase English alphabet letters only. Obviously, it sounds horrible, but that is the least of Bytie's worries. First and foremost, he completely forgot which fragment is he supposed to learn. And they all look quite difficult to memorize... There is hope, however: some parts of the poem exhibit certain regularity. In particular, every now and then a fragment, say ![](http://main.edu.pl/images/OI19/okr-en-tex.1.png), is but a multiple repetition of another fragment, say ![](http://main.edu.pl/images/OI19/okr-en-tex.2.png) (in other words, ![](http://main.edu.pl/images/OI19/okr-en-tex.3.png), i.e., ![](http://main.edu.pl/images/OI19/okr-en-tex.4.png), where ![](http://main.edu.pl/images/OI19/okr-en-tex.5.png) is an integer). In such case we say that ![](http://main.edu.pl/images/OI19/okr-en-tex.6.png) is a full period of ![](http://main.edu.pl/images/OI19/okr-en-tex.7.png) (in particular, every string is its own full period). If a given fragment has a short full period, Bytie's task will be easy. The question remains... which fragment was that? Make a gift for Bytie - write a program that will read the whole poem as well as a list of fragments that Bytie suspects might be the one he is supposed to memorize, and for each of them determines its shortest full period. 给出一个由小写英文字母组成的字符串S,再给出q个询问,要求回答S某个子串的最短循环节。 如果字符串B是字符串A的循环节,那么A可以由B重复若干次得到。

输入输出格式

输入格式


In the first line of the standard input there is a single integer ![](http://main.edu.pl/images/OI19/okr-en-tex.8.png) (![](http://main.edu.pl/images/OI19/okr-en-tex.9.png)). In the second line there is a string of length ![](http://main.edu.pl/images/OI19/okr-en-tex.10.png) consisting of lowercase English alphabet letters-the poem. We number the positions of its successive characters from 1 to ![](http://main.edu.pl/images/OI19/okr-en-tex.11.png). The next line holds a single integer ![](http://main.edu.pl/images/OI19/okr-en-tex.12.png) (![](http://main.edu.pl/images/OI19/okr-en-tex.13.png)) denoting the number of fragments. Then the following ![](http://main.edu.pl/images/OI19/okr-en-tex.14.png) lines give queries, one per line. Each query is a pair of integers ![](http://main.edu.pl/images/OI19/okr-en-tex.15.png) and ![](http://main.edu.pl/images/OI19/okr-en-tex.16.png) (![](http://main.edu.pl/images/OI19/okr-en-tex.17.png)), separated by a single space, such that the answer to the query should be the length of the shortest full period of the poem's fragment that begins at position ![](http://main.edu.pl/images/OI19/okr-en-tex.18.png) and ends at position ![](http://main.edu.pl/images/OI19/okr-en-tex.19.png). In tests worth in total 42% of the points ![](http://main.edu.pl/images/OI19/okr-en-tex.20.png) holds in addition. In some of those, worth 30% of points in total, ![](http://main.edu.pl/images/OI19/okr-en-tex.21.png) holds as well.

输出格式


Your program should print ![](http://main.edu.pl/images/OI19/okr-en-tex.22.png) lines on the standard output. The ![](http://main.edu.pl/images/OI19/okr-en-tex.23.png)-th of these lines should hold a single integer - the answer to the ![](http://main.edu.pl/images/OI19/okr-en-tex.24.png)-th query.

输入输出样例

输入样例 #1

8
aaabcabc
3
1 3
3 8
4 8

输出样例 #1

1
3
5