Hotel
Time limit1sMemory limit128 MB
Process check-in and check-out requests on a row of hotel rooms, always assigning the leftmost block of the requested length, or 0 if none fits.
- Level
Hard8 of 10
- Topics
- Segment tree, Divide and conquer, Binary search
- Solved
- No attempts yet
Problem
A hotel has rooms () arranged in a single row along a hallway, numbered through . Initially every room is empty.
You must process check-in and check-out requests () in order.
- Check-in
1 D(): assign a block of consecutive rooms. Among all starting positions where rooms are all currently empty, choose the smallest , mark those rooms as occupied, and output . If no block of consecutive empty rooms exists, assign nothing and output . - Check-out
2 X D(): mark rooms as empty. Some or all of these rooms may already be empty; that is allowed and has no additional effect.
Input
- Line 1: two integers and .
- The next lines: each line is a request in one of two forms.
1 D— a check-in request for rooms.2 X D— a check-out request for rooms through .
Output
- For each check-in request, print on its own line the number of the first room in the assigned block, or if the request cannot be satisfied. Check-out requests produce no output.