#P2572. Binary Sequence Transformation and Query

    ID: 15841 Type: Default 1000ms 256MiB

Binary Sequence Transformation and Query

Binary Sequence Transformation and Query

You are given a binary sequence of length nn (indexed from 00) that consists of digits 00 and 11. You need to process mm operations. There are five types of operations:

  1. 0 l r: Set all numbers in the interval [l,r][l,r] to 00.
  2. 1 l r: Set all numbers in the interval [l,r][l,r] to 11.
  3. 2 l r: Invert all numbers in the interval [l,r][l,r] (i.e. change every 00 to 11 and every 11 to 00).
  4. 3 l r: Query the total number of 11's in the interval [l,r][l,r].
  5. 4 l r: Query the maximum number of consecutive 11's in the interval [l,r][l,r].

For each query operation (types 3 and 4), you must output the corresponding answer.

Note: All formulas are given in LaTeX format (e.g. [l,r][l, r], 00, 11).

inputFormat

The first line contains two integers nn and mm, where nn is the length of the binary sequence and mm is the number of operations.
The second line contains a binary string of length nn (each character is either '0' or '1').
Each of the next mm lines contains an operation in one of the following formats: \

  • 0 l r\
  • 1 l r\
  • 2 l r\
  • 3 l r\
  • 4 l r

    Here, ll and rr (0lr<n0 \le l \le r < n) denote the indices of the interval.

outputFormat

For each query operation (operations of type 3 and 4), output the answer on a new line. For a type 3 query, output the total number of 11's in the specified interval. For a type 4 query, output the maximum number of consecutive 11's in the interval.

sample

5 6
10101
3 0 4
4 0 4
2 1 3
3 1 3
0 0 1
4 0 4
3

1 2 2

</p>