#P7560. Bookworm Foodstore Queue Simulation

    ID: 20754 Type: Default 1000ms 256MiB

Bookworm Foodstore Queue Simulation

Bookworm Foodstore Queue Simulation

There are \(N\) bookworm foodstores and \(M\) families. Initially, all stores have empty queues. Today, all foodstores open and a series of \(Q\) events occur. The events are of three types:

  • Join event: For every foodstore with an index in the interval \([L, R]\), the family with id \(C\) joins the end of its queue. In each such store, \(K\) persons (representing the family) are added to the tail of the queue.
  • Leave event: For every foodstore with an index in the interval \([L, R]\), if its queue has more than \(K\) persons, then the first \(K\) persons leave the queue; otherwise, the entire queue is cleared.
  • White-glove event: For the foodstore with index \(A\), if its queue has at least \(B\) persons, then the store gives a secret delicacy to the person at the \(B\)-th position in the queue (counting from the front, starting at 1). Otherwise, no one receives the delicacy.

Your task is to simulate all the events and for each white-glove event, output the family id of the person who gets the secret delicacy if the condition is met; otherwise, output -1.

The formulas are given in \(\LaTeX\) format.

inputFormat

The first line contains three integers \(N\), \(M\), and \(Q\) representing the number of foodstores, families, and events respectively. The following \(Q\) lines describe the events. Each event is in one of the following formats:

  • Join event: 1 L R C K
  • Leave event: 2 L R K
  • White-glove event: 3 A B

It is guaranteed that \(1 \le L \le R \le N\) and \(1 \le A \le N\), with other parameters being positive integers.

outputFormat

For each white-glove event (type 3), output a single line containing the family id of the person who gets the secret delicacy if the event condition is satisfied, otherwise output -1.

sample

3 100 6
1 1 3 10 2
3 2 1
2 1 2 1
3 1 2
1 2 2 5 3
3 2 3
10

-1 5

</p>