#abc381e. E - 11/22 Subsequence
E - 11/22 Subsequence
当前没有测试数据。
Score : points
问题陈述
这个问题中11/22字符串的定义与问题A和C中的定义相同。
如果一个字符串满足以下所有条件,则称其为11/22字符串:
- 是奇数。这里,表示的长度。
- 第1个到第个字符都是
1
。 - 第个字符是
/
。 - 第个到第个字符都是
2
。
例如,11/22
、111/222
和/
是11/22字符串,但1122
、1/22
、11/2222
、22/11
和//2/2/211
不是。
给定一个由1
、2
和/
组成的长度为的字符串,处理个查询。
每个查询提供两个整数和。设是从的第个到第个字符的**(连续的)子串。找出中一个子序列(不一定是连续的)**的最大长度,该子序列是一个11/22字符串。如果不存在这样的子序列,则打印0
。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
The definition of an 11/22 string in this problem is the same as in Problems A and C.
A string is called an 11/22 string when it satisfies all of the following conditions:
- is odd. Here, denotes the length of .
- The -st through -th characters are all
1
. - The -th character is
/
. - The -th through -th characters are all
2
.
For example, 11/22
, 111/222
, and /
are 11/22 strings, but 1122
, 1/22
, 11/2222
, 22/11
, and //2/2/211
are not.
Given a string of length consisting of 1
, 2
, and /
, process queries.
Each query provides two integers and . Let be the (contiguous) substring of from the -th through -th character. Find the maximum length of a subsequence (not necessarily contiguous) of that is an 11/22 string. If no such subsequence exists, print 0
.
Constraints
- is a string of length consisting of
1
,2
, and/
. - , , , and are integers.
Input
The input is given from Standard Input in the following format. Here, denotes the -th query.
Each query is given in the following format:
Output
Print lines. The -th line should contain the answer to the -th query.
Sample Input 1
12 5
111/212/1122
1 7
9 12
3 6
4 10
1 12
Sample Output 1
5
0
3
1
7
For the first query, the substring from the -st to -th character of is 111/212
. This string contains 11/22
as a subsequence, which is the longest subsequence that is an 11/22 string. Therefore, the answer is .
For the second query, the substring from the -th to -th character of is 1122
. This string does not contain any subsequence that is an 11/22 string, so the answer is .