Reunion of 1's
Practice
4 (1 votes)
Open
Disjoint Set data structure
Medium
String
Basics of disjoint data structures
Disjoint sets
Data structures
Disjoint data structures
Open
Problem
80% Success 45 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

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 \(X^{th}\) position to \(1\) (It is possible that the character at \(i^{th}\) 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 \(0's\) or \(1's\) 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 \(1's\) in a new line.

Constraints

\(1 \le n,k \le 10^5\)

\(1 \le X \le n\)

String contains only \(0's\) or \(1's\)

Each query is of one of the mentioned types

 

 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
Tags:
mathematicsMedium-HardMedium-Hard
Points:20
24 votes
Tags:
AlgorithmsEasyGraphsHiring
Points:30
62 votes
Tags:
MathematicsOpenApprovedEasy-MediumMathamatics
Editorial

Login to unlock the editorial