#P12571. [UOI 2023] An Array of Characters and Almost Palindromes【交互库尚未配置】
[UOI 2023] An Array of Characters and Almost Palindromes【交互库尚未配置】
题目描述
This is an interactive problem.
A string is considered a palindrome if it reads the same from both sides. Formally, a string of length is considered a palindrome if for . For example, the strings gg
, ara
, abacaba
, and rotator
are palindromes, while the strings array
, palindrome
, and uoi
are not.
We call a string a nearly palindrome if its characters can be rearranged to form a palindrome. For example, the strings n
, ara
, arr
, and array
are nearly palindromes, while the strings palindrome
, uoi
, and random
are not.
A substring of a string is a string that can be obtained by deleting some (possibly zero) elements from its beginning and end.
Let be the maximum length among the lengths of substrings of that are not nearly palindromes, or if there are no such substrings.
You are given a string of length consisting of lowercase Latin letters. You are also given queries of the form , . For each query, find the value of , where denotes the substring consisting of characters .
输入格式
The first line contains one integer () --- the length of the string.
The second line contains a string consisting of lowercase Latin letters.
The third line contains one integer () --- the number of queries.
The fourth line contains two integers () --- the parameters of the first query.
You will receive the parameters of the next queries from the jury program (see section Interaction Protocol).
Interaction Protocol
The jury program will output two integers , () on separate lines for each query, starting from the second one.
The jury program will not output the parameters for the next query until it reads the response of your program to the previous query.
Make sure to call the method after outputting each line. You can use:
- , , or in ;
- in ;
- in ;
- in ;
- consult the documentation for other programming languages.
输出格式
For each -th query, output one integer --- the value of , in a separate line.
8
aabaaaba
3
3 7
1 8
4 4
4
6
0
提示
In the first example, you need to find the answers to three queries:
baaab
, which has a substringaaab
of length 4, which is not an almost palindrome;aabaaaba
, which has a substringaabaaa
of length 6, which is not an almost palindrome;a
, all substrings of which are almost palindromes.
Scoring
- ( points): , , , is even, has the form
aabbaabbaa...
; - ( points): , , , ;
- ( points): , , , ;
- ( points): , , ;
- ( points): contains only letters and ;
- ( points): for ;
- ( points): for ;
- ( points): contains only letters , and ;
- ( points): is odd for ;
- ( points): without additional constraints.