14644 - Big Orange Cat's Parking Lot II   

Description

A parking lot has n parking spaces, each with a size si. There are m events, and each event j is one of two types:

  1. At time tj, a car of size x arrives, preferring parking space lj, and will leave at time tj + aj.
  2. At time tj, check how many parking spaces of size y are available. If a car leaves the parking lot at the moment of a query, the query result reflects the state after the car has left.

For each event of type 1, assign a parking space based on these rules:

  1. Choose the smallest parking space that is >= x.
  2. If multiple spaces meet rule 1, pick the one closest to the preferred space lj.
  3. If multiple spaces meet rule 2, choose the one with the smallest index.
  4. If no space meets rule 1, output -1 and skip the operation.

Input

The first line contains two positive integers n and m, representing the number of parking spaces and the number of events.

The second line contains n positive integers s1 to sn, representing the size of each parking space.

The next m lines each describe an event, with event i presented in one of two formats:

  1. 1 ti x li ai: At time ti, a car of size x arrives, preferring to park as close as possible to space li, and will stay for ai time units.
  2. 2 ti y: At time ti, query how many parking spaces of size y are available.

Output

For each car arrival event, output the assigned parking space number, or -1 if no space can be assigned. For each parking space query event, output the corresponding result.

Constraints

  • 1 <= n, m <= 2 * 105
  • 1 <= si, ti, x, ai, y <= 109
  • ti - 1 < ti
  • 1 <= l<= n

Subtasks

  • Testcase 1: Each parking space has a unique size, and whenever a vehicle arrives, there is always a parking space of size = x available, ai = 109
  • Testcase 2: ai = 109, li = 1
  • Testcases 3, 4: li = 1
  • Testcase 5: ai = 109
  • Testcases 6, 7: No additional constraints.

Sample Input  Download

Sample Output  Download

Tags




Discuss