#C8930. Parking Lot Management

    ID: 52967 Type: Default 1000ms 256MiB

Parking Lot Management

Parking Lot Management

This problem simulates the management of a parking lot. Cars arrive and are parked in the smallest available numbered slot. When a car leaves from a slot, that slot becomes available for future use. More formally, when a parking operation (denoted by 1) occurs, the car gets the minimum available slot number; if no slot is available, the car is assigned a new slot with the next integer. When a leaving operation (denoted by 2 x) occurs, the car in slot x leaves, and the slot becomes available.

The operations are processed sequentially. For each parking operation, output the assigned parking slot number.

The solution requires careful handling of the available slots. If we denote by \( S \) the set of available slots (when a car leaves) and by \( L \) the last assigned slot number, then the parking operation can be defined as:

[ \text{position} = \begin{cases} \min(S) & \text{if } S \neq \emptyset, \ L+1 & \text{otherwise.} \end{cases} ]

inputFormat

The first line of input contains an integer n representing the number of queries. Each of the next n lines contains a query. A query is either:

  • 1 indicating a parking operation, or
  • 2 x indicating that the car in parking slot x leaves.

outputFormat

Output a single line containing the parking slot numbers assigned for each parking operation (1). The numbers should be separated by a single space. If there are no parking operations, output an empty line.

## sample
5
1
1
2 1
1
1
1 2 1 3