CF2164H.PalindromePalindrome
NOI/NOI+/CTSC
通过率:0%
时间限制:5.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
We define the humor value of a string t as the length of the longest palindrome string which occurs at least twice in it.
Formally, a string p is humor with respect to t, if and only if both of the following conditions are met:
- p is a palindrome, and
- there exist at least two different indices i∈[1,∣t∣−∣p∣+1], such that t[i,i+∣p∣−1]=p.
The humor value of t is defined as the maximum length among all humor strings with respect to t.
You are given a string s of length n which only contains lowercase Latin letters and q queries. Each query contains two integers li, ri, and you need to find the humor value of the string s[li,ri].
Here, a[l,r] is defined as the string al,al+1,…,ar.
我们定义字符串 t 的幽默值为:在 t 中至少出现两次的最长回文子串的长度。
形式化地,字符串 p 关于 t 是“幽默的”,当且仅当同时满足以下两个条件:
- p 是一个回文串;
- 存在至少两个不同的下标 i∈[1,∣t∣−∣p∣+1],使得 t[i,i+∣p∣−1]=p。
字符串 t 的幽默值被定义为所有关于 t 幽默的字符串中长度的最大值。
给定一个长度为 n 的字符串 s,其中仅包含小写拉丁字母,以及 q 个查询。每个查询包含两个整数 li、ri,你需要求出子串 s[li,ri] 的幽默值。
此处,a[l,r] 表示字符串 al,al+1,…,ar。
输入格式
The first line contains two integers n, q (1≤n,q≤5⋅105).
The second line contains a string s.
The next q lines contain the description of queries. The i-th line contains two integers li, ri (1≤li≤ri≤n).
第一行包含两个整数 n、q(1≤n,q≤5⋅105)。
第二行包含一个字符串 s。
接下来的 q 行描述了查询。第 i 行包含两个整数 li、ri(1≤li≤ri≤n)。
输出格式
On the i-th line, output the answer to the i-th query.
在第 i 行输出第 i 个查询的答案。
输入输出样例
输入#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 4.
In the second query, one of the longest humor strings with respect to s[2,7] is aa.
在第一次查询中,以下回文字符串至少出现两次:a、aa、aaa、aaaa、b、bb、bbb。其中最长的是 aaaa,因此幽默值为 4。
在第二次查询中,关于子串 s[2,7] 的一个最长幽默字符串是 aa。
输入解题思路,AI测评打分。不知道怎么写?