#P2572. Binary Sequence Transformation and Query
Binary Sequence Transformation and Query
Binary Sequence Transformation and Query
You are given a binary sequence of length (indexed from ) that consists of digits and . You need to process operations. There are five types of operations:
- 0 l r: Set all numbers in the interval to .
- 1 l r: Set all numbers in the interval to .
- 2 l r: Invert all numbers in the interval (i.e. change every to and every to ).
- 3 l r: Query the total number of 's in the interval .
- 4 l r: Query the maximum number of consecutive 's in the interval .
For each query operation (types 3 and 4), you must output the corresponding answer.
Note: All formulas are given in LaTeX format (e.g. , , ).
inputFormat
The first line contains two integers and , where is the length of the binary sequence and is the number of operations.
The second line contains a binary string of length (each character is either '0' or '1').
Each of the next 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, and () 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 's in the specified interval. For a type 4
query, output the maximum number of consecutive '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>