All Tracks Data Structures Advanced Data Structures Segment Trees Problem

Zeros and Ones
/

BIT, Data Structures, Segment tree

Problem
Editorial
Analytics

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\)

SAMPLE INPUT
6
3
1 5
0 2
1 5
SAMPLE OUTPUT
5
6
Explanation

The initial array A: \([1, 1, 1, 1, 1, 1]\)

  1. \(5^{th}\) one is at position 5.
  2. Update the \(2^{nd}\) index to zero. After update array A: \([1, 0, 1, 1, 1, 1]\)
  3. \(5^{th}\) one is at position 6.
Time Limit: 2.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB

Best Submission

Similar Problems

Contributors

This Problem was Asked in

Initializing Code Editor...
Notifications
View All Notifications

?