Problem10291--CF EDU - Segment Tree P2 - Step 3 - B. Inverse and K-th one

10291: CF EDU - Segment Tree P2 - Step 3 - B. Inverse and K-th one

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 512 MiB

Description

There is an array of $n$ booleans, initially filled with zeros. You need to write a data structure that processes two types of queries:

  • change the value of all elements on a segment from $l$ to $r−1$ to the opposite,
  • find the index of the $k$-th one.

Input

The first line contains two numbers $n, m\ (1≤n,m≤100,000)$, the size of the array and the number of operations. 

The following lines contain the description of the operations. The description of each operation is as follows:

  • 1 l r: change the value of all elements on a segment from $l$ to $r−1$ to the opposite $(0≤l<r≤n)$,
  • 2 k: the index of the $k$-th one (ones are numbered from 0, it is guaranteed that there are enough ones in the array).

Output

For each operation of the second type, print the index of the corresponding one (all indices in this problem are from 0).

Sample 1 Input

5 7
1 1 3
2 1
1 0 2
2 0
2 1
1 0 5
2 2

Sample 1 Output

2
0
2
4

HINT

CF EDU.

Source/Category