Zeros and Ones
Practice
4.5 (42 votes)
Bit manipulation
Data structures
Easy
Segment trees
Problem
77% Success 11932 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code

You are given an array A which contains initially only ones. You can perform two operations:

  1. \(0\;I\): Given an index I, update the value of \(A_I\) to zero.
  2. \(1\;K\): Given the value K, print the index of \(K^{th}\) one in the array A. If there is no such index then print 1.

Input:
The first line of input contains N, the size of the array. The second line contains Q, number of operations. Next Q line contains one of the two operations.

Output:
Print the output for the second type of queries in a new line.

Constraints:
\(1 \le N \le 10^6\)
\(1 \le Q \le 10^6\)
\(1 \le I \le N\)
\(1 \le K \le N\)

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:20
32 votes
Tags:
Advanced Data StructuresBit ManipulationData StructuresEasySegment Trees
Points:20
19 votes
Tags:
Advanced Data StructuresBit ManipulationData StructuresEasySegment Trees
Points:20
29 votes
Tags:
Advanced Data StructuresData StructuresEasySegment Trees