Zeros and Ones

4.5

42 votes
Bit Manipulation, Data Structures, Easy, Segment Trees
Problem

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

  1. 0I: Given an index I, update the value of AI to zero.
  2. 1K: Given the value K, print the index of Kth 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:
1N106
1Q106
1IN
1KN

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

The initial array A: [1,1,1,1,1,1]

  1. 5th one is at position 5.
  2. Update the 2nd index to zero. After update array A: [1,0,1,1,1,1]
  3. 5th one is at position 6.
Editor Image

?