P3538 [POI2012]OKR-A Horrible Poem

    • 84通过
    • 325提交
  • 题目提供者 洛谷OnlineJudge
  • 评测方式 云端评测
  • 标签 哈希,HASH POI 2012 高性能
  • 难度 省选/NOI-
  • 时空限制 1000ms / 128MB

题解

  • 提示:收藏到任务计划后,可在首页查看。
  • 最新讨论 显示

    推荐的相关题目 显示

    题目描述

    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 , is but a multiple repetition of another fragment, say (in other words, , i.e., , where is an integer). In such case we say that is a full period of (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 ().

    In the second line there is a string of length consisting of lowercase English alphabet letters-the poem.

    We number the positions of its successive characters from 1 to .

    The next line holds a single integer () denoting the number of fragments.

    Then the following lines give queries, one per line.

    Each query is a pair of integers and (), 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 and ends at position .

    In tests worth in total 42% of the points holds in addition.

    In some of those, worth 30% of points in total, holds as well.

    输出格式:

    Your program should print lines on the standard output.

    The -th of these lines should hold a single integer - the answer to the -th query.

    输入输出样例

    输入样例#1: 复制
    8
    aaabcabc
    3
    1 3
    3 8
    4 8
    输出样例#1: 复制
    1
    3
    5

    说明

    给出一个由小写英文字母组成的字符串S,再给出q个询问,要求回答S某个子串的最短循环节。

    如果字符串B是字符串A的循环节,那么A可以由B重复若干次得到。

    提示
    标程仅供做题后或实在无思路时参考。
    请自觉、自律地使用该功能并请对自己的学习负责。
    如果发现恶意抄袭标程,将按照I类违反进行处理。