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:
- \(0\;I\): Given an index I, update the value of \(A_I\) to zero.
- \(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\)
Explanation
The initial array A: \([1, 1, 1, 1, 1, 1]\)
- \(5^{th}\) one is at position 5.
- Update the \(2^{nd}\) index to zero. After update array A: \([1, 0, 1, 1, 1, 1]\)
- \(5^{th}\) one is at position 6.
Code Editor
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
Submissions
Please login to view your submissions
Similar Problems
1.Xor sum
Points:20
19 votes
Tags:
Advanced Data StructuresBit ManipulationData StructuresEasySegment Trees
Points:20
29 votes
Tags:
Advanced Data StructuresData StructuresEasySegment Trees
Points:20
32 votes
Tags:
Advanced Data StructuresBit ManipulationData StructuresEasySegment Trees
Editorial
Login to unlock the editorial
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