Reunion of 1's

0

0 votes
Open, Medium, String, Data Structures, Open, Disjoint data structures, Disjoint set, Disjoint set
Problem

You are given a string of size n that consists of 0s or 1s. You are required to perform total k queries and there are the following types of queries:

  1. 1: Print the length of the longest subarray that consists of only 1s.
  2. 2 X: Here, X is an integer between 1 to n. In this query, you can change the character that is available at the Xth position to 1 (It is possible that the character at ith position was already 1).

Input format

  • First line: n and k denoting the length of the string and the number of queries
  • Next line: A string of 0s or 1s of length n
  • Each of the next k lines: Query of type 1 or 2

Output format

For each query of type 1, print the maximum size of the subarray with all 1s in a new line.

Constraints

1n,k105

1Xn

String contains only 0s or 1s

Each query is of one of the mentioned types

 

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation
  • Initially there are no 1's in the string, hence the answer is 0.
  • In second query of type '1' state of string is 00100, hence answer is 1.
  • In Third query of type '1' state of string is 00101, hence answer is 1.
  • In Fourth query of type '1' state of string is 00111, hence answer is 3.
Editor Image

?