#K95537. Longest Consecutive Ones and Array Operations

    ID: 38885 Type: Default 1000ms 256MiB

Longest Consecutive Ones and Array Operations

Longest Consecutive Ones and Array Operations

In this problem, you are given an array of integers consisting only of 0s and 1s. You will perform a sequence of operations on the array. There are two types of operations:

  • flip i: Flip the element at index \(i\) (0-indexed), i.e., change 0 to 1 and 1 to 0.
  • query: Report the length of the longest consecutive sequence of 1s in the current state of the array.

You need to process a series of test cases. Each test case begins with two integers \(n\) and \(m\) where \(n\) is the number of elements in the array and \(m\) is the number of operations. The next line contains \(n\) integers (each either 0 or 1). This is followed by \(m\) lines where each line is an operation. The end of input is signaled by a line with "0 0".

The task is to execute the operations in order and print the result of each "query" operation on a new line.

inputFormat

The input contains multiple test cases. Each test case has the following format:

n m
a0 a1 ... an-1
operation1
operation2
...
operationm

The operations are either of the form "flip i" (to flip the element at index \(i\)) or "query" (to query the current longest run of 1s). The input is terminated by a test case that starts with "0 0", which should not be processed.

outputFormat

For each "query" operation, output the length of the longest consecutive sequence of 1s, each on its own line.

## sample
6 5
1 0 1 1 0 1
query
flip 1
query
flip 3
query
0 0
2

4 3

</p>