Conference Hotel Blocks
A conference hotel has a single long corridor of n rooms, numbered 1 to n from the elevator.
Event organisers call the front desk to reserve a block of rooms for their group: a block must be
k adjacent rooms, so that the whole group stays together. The booking system always hands out the
block closest to the elevator, which keeps the far end of the corridor free for late arrivals.
At the start every room is free. The desk then processes q requests in order:
book k: find the smallestxsuch that roomsx, x+1, …, x+k−1are all free. If such anxexists, thosekrooms become occupied and the answer isx. Otherwise nothing changes and the answer is0.checkout l r: every room fromltorinclusive becomes free. Some of these rooms may already be free; they simply stay free. A checkout may cover parts of several blocks, and part of a block may be checked out while the rest stays occupied.
Report the answer to every book request.
Input
The first line contains two integers n and q (1 ≤ n ≤ 2·10^5, 1 ≤ q ≤ 2·10^5): the number of
rooms and the number of requests.
Each of the next q lines contains one request, either book k (1 ≤ k ≤ n) or checkout l r
(1 ≤ l ≤ r ≤ n). At least one request is a book request.
Output
For every book request, in input order, print one line with the number of the first room of the
assigned block, or 0 if no k adjacent rooms are free.
Notes
In the first example the corridor has 10 rooms. The first three bookings take rooms 1–3, 4–5 and
6–9. A block of 2 no longer fits (only room 10 is free), so the fourth answer is 0. After rooms 2
to 4 are checked out, the free rooms are 2, 3, 4 and 10, so the block of 3 starts at room 2 and the
block of 1 gets room 10.
In the second example, after the two checkouts the free rooms are 3–5 and 8–10. The block of 4 does not fit anywhere, and the block of 3 goes to the lower-numbered run, starting at room 3.