D. 「一本通 2.1 练习 4」A Horrible Poem

    Type: Default 1200ms 512MiB

「一本通 2.1 练习 4」A Horrible Poem

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Description

Original source: POI 2012

Given a string S S consisting of lowercase English letters, and q q queries, each query asks for the length of the shortest cycle in a substring of S S .

A string B B is a cycle of string A A if A A can be formed by repeating B B multiple times.

Input Format

The first line contains a positive integer n n , the length of S S .
The second line contains n n lowercase English letters, representing the string S S .
The third line contains a positive integer q q , the number of queries.
The following q q lines each contain two positive integers a a and b b , representing the query for the substring S[a..b] S[a..b] and asking for the length of its shortest cycle.

Output Format

Output q q lines of positive integers, where the i i -th line corresponds to the answer for the i i -th query.

Sample 1

8
aaabcabc
3
1 3
3 8
4 8

1
3
5

Constraints and Hints

1abn5×105, 1 \le a \le b \le n \le {5\times 10^5} , q2×106 q \le {2\times 10 ^ 6} .

20251117 D班作业(6)

Not Claimed
Status
Done
Problem
4
Open Since
2025-11-17 0:00
Deadline
2025-11-25 23:59
Extension
24 hour(s)