This page is still under construction.

Parts of this page are still being built. What you see may change.

Hotel

Time limit1sMemory limit128 MB

Summary
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 NN rooms (1≤N≤50,0001 \le N \le 50{,}000) arranged in a single row along a hallway, numbered 11 through NN. Initially every room is empty.

You must process MM check-in and check-out requests (1≤M<50,0001 \le M < 50{,}000) in order.

  • Check-in 1 D (1≤D≤N1 \le D \le N): assign a block of DD consecutive rooms. Among all starting positions rr where rooms r,r+1,…,r+D−1r, r+1, \dots, r+D-1 are all currently empty, choose the smallest rr, mark those rooms as occupied, and output rr. If no block of DD consecutive empty rooms exists, assign nothing and output 00.
  • Check-out 2 X D (1≤X≤N−D+11 \le X \le N-D+1): mark rooms X,X+1,…,X+D−1X, X+1, \dots, X+D-1 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 NN and MM.
  • The next MM lines: each line is a request in one of two forms.
    • 1 D — a check-in request for DD rooms.
    • 2 X D — a check-out request for rooms XX through X+D−1X+D-1.

Output

  • For each check-in request, print on its own line the number rr of the first room in the assigned block, or 00 if the request cannot be satisfied. Check-out requests produce no output.

Examples3

  1. Example 1

    Input
    10 6
    1 3
    1 3
    1 3
    1 3
    2 5 5
    1 6
    
    Expected output
    1
    4
    7
    0
    5
    
  2. Example 2

    Input
    1 4
    1 1
    1 1
    2 1 1
    1 1
    
    Expected output
    1
    0
    1
    
  3. Example 3

    Input
    5 4
    1 5
    1 1
    2 2 2
    1 2
    
    Expected output
    1
    0
    2