Under construction

Still being built. Things may change

Charging

Interview

Time limit2sMemory limit1024 MB

Summary
Each plug request takes the smallest empty port numbered at least i, and each unplug query reports which action filled that port.
Level

Medium5 of 10

Topics
Segment tree, Implementation, Hash map
Solved
No attempts yet

Problem

Dongwoo uses many different electronic devices. Carrying every charger was a hassle, so Dongwoo bought a multi-port charger with NN ports. Unlike ordinary chargers, each port outputs a different amount of power. Port ii outputs ii units of power.

During the next QQ actions, Dongwoo plugs devices into the charger or unplugs them. There are two kinds of action, given as input in the following format.

  • 1 ii: Plug in a device whose minimum required power is ii into port ii. If port ii already has a device, plug the device into the empty port with the smallest power that is at least the minimum power ii. If every empty port has less power than ii, do not plug in the device.
  • 2 ii: If a device is plugged into port ii, unplug it.

Input

The first line contains the number of ports NN (1≤N≤1061 \leq N \leq 10^{6}) and the number of actions QQ (1≤Q≤1061 \leq Q \leq 10^{6}). Each of the next QQ lines contains an action type tt (t∈{1,2}t \in \{1, 2\}) and an integer ii (1≤i≤N1 \leq i \leq N), separated by a space.

Output

For each action, print the result on its own line.

For a 1 action, print the port number if the device was plugged in, or -1 if it was not.

For a 2 action, print the number of the action that plugged in the device currently in port ii if there is one, or -1 if the port is empty. Actions of both types are counted together, starting from 1.

Examples2

  1. Example 1

    Input
    2 11
    1 2
    1 2
    1 1
    2 1
    2 2
    1 1
    1 1
    1 1
    2 1
    1 2
    1 1
    
    Expected output
    2
    -1
    1
    3
    1
    1
    2
    -1
    6
    -1
    1
    
  2. Example 2

    Input
    6 13
    1 3
    1 5
    1 3
    1 3
    1 3
    1 1
    1 6
    2 5
    2 6
    1 2
    1 1
    1 1
    1 1
    
    Expected output
    3
    5
    4
    6
    -1
    1
    -1
    2
    4
    2
    5
    6
    -1