#abc322f. F - Vacation Query

F - Vacation Query

Score : 550550 points

问题描述

你得到一个长度为 NN 的字符串 SS,由 01 组成。令 SiS_i 表示 SS 中的第 ii 个字符。

按照给定顺序处理 QQ 个查询操作。每个查询由一个包含三个整数的元组 (c,L,R)(c, L, R) 表示,其中 cc 表示查询的类型。

  • c=1c=1 时:对于满足 LiRL \leq i \leq R 的每个整数 ii,如果 SiS_i1,将其改为 0;如果它是 0,则将其改为 1
  • c=2c=2 时:获取从第 LL 个到第 RR 个字符组成的子字符串 TT。输出 TT 中连续 1s 的最大数量。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a string SS of length NN consisting of 0 and 1. Let SiS_i denote the ii-th character of SS.

Process QQ queries in the order they are given.
Each query is represented by a tuple of three integers (c,L,R)(c, L, R), where cc represents the type of the query.

  • When c=1c=1: For each integer ii such that LiRL \leq i \leq R, if SiS_i is 1, change it to 0; if it is 0, change it to 1.
  • When c=2c=2: Let TT be the string obtained by extracting the LL-th through RR-th characters of SS. Print the maximum number of consecutive 1s in TT.

Constraints

  • 1N5×1051 \leq N \leq 5 \times 10^5
  • 1Q1051 \leq Q \leq 10^5
  • SS is a string of length NN consisting of 0 and 1.
  • c{1,2}c \in \lbrace 1, 2 \rbrace
  • 1LRN1 \leq L \leq R \leq N
  • NN, QQ, cc, LL, and RR are all integers.

Input

The input is given from Standard Input in the following format, where queryi\mathrm{query}_i represents the ii-th query:

NN QQ

SS

query1\mathrm{query}_1

query2\mathrm{query}_2

\vdots

queryQ\mathrm{query}_Q

Each query is given in the following format:

cc LL RR

Output

Let kk be the number of queries with c=2c=2. Print kk lines.
The ii-th line should contain the answer to the ii-th query with c=2c=2.

Sample Input 1

7 6
1101110
2 1 7
2 2 4
1 3 6
2 5 6
1 4 7
2 1 7

Sample Output 1

3
1
0
7

The queries are processed as follows.

  • Initially, S=S= 1101110.
  • For the first query, T=T = 1101110. The longest sequence of consecutive 1s in TT is 111 from the 44-th character to 66-th character, so the answer is 33.
  • For the second query, T=T = 101. The longest sequence of consecutive 1s in TT is 1 at the 11-st or 33-rd character, so the answer is 11.
  • For the third query, the operation changes SS to 1110000.
  • For the fourth query, T=T = 00. TT does not contain 1, so the answer is 00.
  • For the fifth query, the operation changes SS to 1111111.
  • For the sixth query, T=T = 1111111. The longest sequence of consecutive 1s in TT is 1111111 from the 11-st to 77-th characters, so the answer is 77.

update @ 2024/3/10 01:43:09