#abc341e. E - Alternating String

E - Alternating String

Score: 450450 points

问题描述

01 组成的字符串,如果其中任意两个相邻的字符都不同,则被称为好字符串

给定一个长度为 NN 的仅包含 01 的字符串 SS。将会有 QQ 个查询按顺序进行处理。

查询有两种类型:

  • 1 L R:翻转 SS 中从第 LL 个到第 RR 个字符。也就是说,对于满足 LiRL\leq i\leq R 的每个整数 ii,如果第 ii 个字符是 1,则将其变为 0;反之亦然。
  • 2 L R:令 SS' 为通过提取 SS 中从第 LL 个到第 RR 个字符(保持原有顺序)得到的长度为 (RL+1)(R-L+1) 的字符串。若 SS' 是好字符串,则输出 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 SS of length NN consisting of 0 and 1. QQ queries will be given and must be processed in order.
There are two types of queries:

  • 1 L R: Flip each of the LL-th to RR-th characters of SS. That is, for each integer ii satisfying LiRL\leq i\leq R, change the ii-th character of SS to 0 if it is 1, and vice versa.
  • 2 L R: Let SS' be the string of length (RL+1)(R-L+1) obtained by extracting the LL-th to RR-th characters of SS (without changing the order). Print Yes if SS' is a good string and No otherwise.

Constraints

  • 1N,Q5×1051\leq N, Q\leq 5\times 10^5
  • SS is a string of length NN consisting of 0 and 1.
  • 1LRN1\leq L\leq R\leq N for queries of types 11 and 22.
  • There is at least one query of type 22.
  • NN, QQ, LL, and RR are integers.

Input

The input is given from Standard Input in the following format:

NN QQ

SS

query1query_1

query2query_2

\vdots

queryQquery_Q

Each query queryiquery_i (1iQ)(1\leq i\leq Q) is given in the form:

11 LL RR

or:

22 LL RR

Output

Let KK be the number of queries of type 22. Print KK lines.
The ii-th line should contain the response to the ii-th query of type 22.

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, S=S=10100. When processing the queries in the order they are given, the following occurs:

  • For the first query, the string obtained by extracting the 11-st to 33-rd characters of SS is S=S'=101. This is a good string, so print Yes.
  • For the second query, the string obtained by extracting the 11-st to 55-th characters of SS is S=S'=10100. This is not a good string, so print No.
  • For the third query, flip each of the 11-st to 44-th characters of SS. The string SS becomes S=S=01010.
  • For the fourth query, the string obtained by extracting the 11-st to 55-th character of SS is S=S'=01010. This is a good string, so print Yes.
  • For the fifth query, flip the 33-rd character of SS. The string SS becomes S=S=01110.
  • For the sixth query, the string obtained by extracting the 22-nd to 44-th character of SS is S=S'=111. This is not a good string, so print No.

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

}