#abc341e. E - Alternating String
E - Alternating String
Score: points
问题描述
由 0
和 1
组成的字符串,如果其中任意两个相邻的字符都不同,则被称为好字符串。
给定一个长度为 的仅包含 0
和 1
的字符串 。将会有 个查询按顺序进行处理。
查询有两种类型:
1 L R
:翻转 中从第 个到第 个字符。也就是说,对于满足 的每个整数 ,如果第 个字符是1
,则将其变为0
;反之亦然。2 L R
:令 为通过提取 中从第 个到第 个字符(保持原有顺序)得到的长度为 的字符串。若 是好字符串,则输出Yes
,否则输出No
。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
A string consisting of 0
and 1
is called a good string if two consecutive characters in the string are always different.
You are given a string of length consisting of 0
and 1
. queries will be given and must be processed in order.
There are two types of queries:
1 L R
: Flip each of the -th to -th characters of . That is, for each integer satisfying , change the -th character of to0
if it is1
, and vice versa.2 L R
: Let be the string of length obtained by extracting the -th to -th characters of (without changing the order). PrintYes
if is a good string andNo
otherwise.
Constraints
- is a string of length consisting of
0
and1
. - for queries of types and .
- There is at least one query of type .
- , , , and are integers.
Input
The input is given from Standard Input in the following format:
Each query is given in the form:
or:
Output
Let be the number of queries of type . Print lines.
The -th line should contain the response to the -th query of type .
Sample Input 1
5 6
10100
2 1 3
2 1 5
1 1 4
2 1 5
1 3 3
2 2 4
Sample Output 1
Yes
No
Yes
No
Initially, 10100
. When processing the queries in the order they are given, the following occurs:
- For the first query, the string obtained by extracting the -st to -rd characters of is
101
. This is a good string, so printYes
. - For the second query, the string obtained by extracting the -st to -th characters of is
10100
. This is not a good string, so printNo
. - For the third query, flip each of the -st to -th characters of . The string becomes
01010
. - For the fourth query, the string obtained by extracting the -st to -th character of is
01010
. This is a good string, so printYes
. - For the fifth query, flip the -rd character of . The string becomes
01110
. - For the sixth query, the string obtained by extracting the -nd to -th character of is
111
. This is not a good string, so printNo
.
Sample Input 2
1 2
1
1 1 1
2 1 1
Sample Output 2
Yes
Note that a string of a single character 0
or 1
satisfies the condition of being a good string.
update @ 2024/3/10 01:35:05