Charging
InterviewTime limit2sMemory limit1024 MB
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 ports. Unlike ordinary chargers, each port outputs a different amount of power. Port outputs units of power.
During the next actions, Dongwoo plugs devices into the charger or unplugs them. There are two kinds of action, given as input in the following format.
1: Plug in a device whose minimum required power is into port . If port already has a device, plug the device into the empty port with the smallest power that is at least the minimum power . If every empty port has less power than , do not plug in the device.2: If a device is plugged into port , unplug it.
Input
The first line contains the number of ports () and the number of actions (). Each of the next lines contains an action type () and an integer (), 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 if there is one, or -1 if the port is empty. Actions of both types are counted together, starting from 1.