CF2164H.PalindromePalindrome

NOI/NOI+/CTSC

通过率:0%

时间限制:5.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

We define the humor value of a string tt as the length of the longest palindrome string which occurs at least twice in it.

Formally, a string pp is humor with respect to tt, if and only if both of the following conditions are met:

  1. pp is a palindrome, and
  2. there exist at least two different indices i∈[1,∣t∣−∣p∣+1]i \in [1, |t| - |p| + 1], such that t[i,i+∣p∣−1]=pt[i, i + |p| - 1] = p.

The humor value of tt is defined as the maximum length among all humor strings with respect to tt.

You are given a string ss of length nn which only contains lowercase Latin letters and qq queries. Each query contains two integers lil_i, rir_i, and you need to find the humor value of the string s[li,ri]s[l_i, r_i].

Here, a[l,r]a[l, r] is defined as the string al,al+1,…,ara_l,a_{l+1},\ldots,a_r.

我们定义字符串 tt 的幽默值为:在 tt 中至少出现两次的最长回文子串的长度。

形式化地,字符串 pp 关于 tt 是“幽默的”,当且仅当同时满足以下两个条件:

  1. pp 是一个回文串;
  2. 存在至少两个不同的下标 i∈[1,∣t∣−∣p∣+1]i \in [1, |t| - |p| + 1],使得 t[i,i+∣p∣−1]=pt[i, i + |p| - 1] = p。

字符串 tt 的幽默值被定义为所有关于 tt 幽默的字符串中长度的最大值。

给定一个长度为 nn 的字符串 ss,其中仅包含小写拉丁字母,以及 qq 个查询。每个查询包含两个整数 lil_i、rir_i,你需要求出子串 s[li,ri]s[l_i, r_i] 的幽默值。

此处,a[l,r]a[l, r] 表示字符串 al,al+1,…,ara_l,a_{l+1},\ldots,a_r。

输入格式

The first line contains two integers nn, qq (1≤n,q≤5⋅1051\le n,q\le 5\cdot10^5).

The second line contains a string ss.

The next qq lines contain the description of queries. The ii-th line contains two integers lil_i, rir_i (1≤li≤ri≤n1\le l_i\le r_i\le n).

第一行包含两个整数 nn、qq(1≤n,q≤5⋅1051\le n,q\le 5\cdot10^5)。

第二行包含一个字符串 ss。

接下来的 qq 行描述了查询。第 ii 行包含两个整数 lil_i、rir_i(1≤li≤ri≤n1\le l_i\le r_i\le n)。

输出格式

On the ii-th line, output the answer to the ii-th query.

在第 ii 行输出第 ii 个查询的答案。

输入输出样例

  • 输入#1

    12 6
    aaaabbbbaaaa
    1 12
    2 7
    3 10
    4 7
    5 9
    4 5

    输出#1

    4
    2
    3
    2
    3
    0

说明/提示

In the first query, the following palindrome strings occur at least twice: a,aa,aaa,aaaa,b,bb,bbb. The longest one is aaaa, so the humor value is 44.

In the second query, one of the longest humor strings with respect to s[2,7]s[2, 7] is aa.

在第一次查询中,以下回文字符串至少出现两次:a、aa、aaa、aaaa、b、bb、bbb。其中最长的是 aaaa,因此幽默值为 44。

在第二次查询中,关于子串 s[2,7]s[2, 7] 的一个最长幽默字符串是 aa。

输入解题思路,AI测评打分。不知道怎么写?

首页