P10711 [NOISG 2024 Prelim] Amusement Park

Background

Translated from [NOI SG 2024 Prelim D.Amusement Park](https://github.com/noisg/noi-2024-prelim).

Description

There is an amusement park that provides a sightseeing cart service at the entrance. Obviously, each cart can carry only a limited number of people, so when a group arrives at the entrance and finds that there are not enough seats, they need to decide whether they are willing to split up. Some groups are willing, and some are not. To solve this complicated problem, the park manager, Snail Stuart, wants you to help write a program that supports the following three operations: - `join`: A new group enters the queue. We use two integers $s, w$ to describe this operation: $s$ is the total number of people in the group; if $w = 1$, then this group is willing to split up when boarding a cart; if $w = 0$, they are not willing to split up. Suppose this operation is the $i$-th `join` operation among all operations, then the group ID is $i$. - `leave`: Given $i$, the group with ID $i$ leaves the queue. - `board`: Given $b$, meaning a new cart arrives with $b$ seats. Starting from the front of the queue, when reaching a group, if the cart can carry all people in the group, then everyone boards; otherwise, if the group is willing to split up, then some people board; otherwise, the group stays in its original position, and the same process is repeated for the next group, until the cart is full, or no one is willing to board.

Input Format

The first line contains an integer $q$. The next $q$ lines each describe one operation, in one of the following three forms: - `1 s w`: describes a `join` operation. - `2 i`: describes a `leave` operation. - `3 b`: describes a `board` operation.

Output Format

For `join` and `leave` operations, you do not need to output anything. For each `board` operation, suppose there are $k$ groups with at least one person boarding the cart. You need to output $k + 1$ lines: - The first line contains an integer $k$. - The next $k$ lines each contain two integers: the first is the group ID, and the second is the number of people from that group who board the cart. **Note: group IDs should be output in increasing order.** (If $k = 0$, ignore this part.)

Explanation/Hint

### Constraints |$\text{Subtask}$|Score|Special Properties| |:-:|:-:|:-:| |$0$|$0$|Sample| |$1$|$12$|$q \le 1000$| |$2$|$7$|$s = 1, w = 0$, no `leave` operations| |$3$|$20$|$s \le 10, w = 0$, no `leave` operations| |$4$|$16$|$s \le 10$, no `leave` operations| |$5$|$10$|$s \le 10$| |$6$|$35$|No special properties| For $100\%$ of the testdata: - $1 \le q \le 200000$. - For all `join` operations, $1 \le s \le 200000, 0 \le w \le 1$. - For all `leave` operations, it is guaranteed that every $i$ is in the queue at the time of the operation. - For all `board` operations, $1 \le b \le 10^{12}$. - There is at least one `board` operation. Translated by ChatGPT 5