Zeros and Ones
Tag(s):

## BIT, Data Structures, Easy, Segment Trees

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
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), TypeScript, Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, Visual Basic

## CODE EDITOR

Initializing Code Editor...

## This Problem was Asked in Challenge Name

Tower Research C++ Developer Hiring Challenge

OTHER PROBLEMS OF THIS CHALLENGE
• Algorithms > String Algorithms
• Algorithms > Dynamic Programming

?