P27725 [洛谷] [NOISG2024 Prelim] Amusement Park
入门
题目描述

Problem Description

There is an amusement park with a sightseeing car service at the entrance. Obviously, a sightseeing car can only accommodate a limited number of people. When a group arrives at the entrance and finds that the car is not big enough, they need to decide whether they are willing to split up. Some groups are willing, while others are not.

To solve this complex 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 describe this operation with two integers $s, w$: $s$ represents the total number of people in the group; if $w=1$, the group is willing to split when boarding the sightseeing car; if $w=0$, they are not willing to split. Assuming this operation is the $i$-th join operation among all operations, the group is assigned the number $i$.

  • leave: Given $i$, the group numbered $i$ leaves the queue.

  • board: Given $b$, a new sightseeing car arrives that can seat $b$ people. Starting from the front of the queue, if a group can fit entirely into the car, everyone boards; otherwise, if the group is willing to split, some people board; otherwise, the group stays in place, and the process repeats for the next group until the car is full or no one is willing to board.

Input Format

The first line contains an integer $q$.

The next $q$ lines each describe an operation, which can be one of the following three types:

  • 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, let there be $k$ groups with at least one person boarding the sightseeing car. You need to output $k+1$ lines:

  • The first line contains an integer $k$.

  • The next $k$ lines, each containing two integers, the first being the group number and the second being the number of people from that group who boarded the car. Note: Group numbers should be output in ascending order. (If $k=0$, ignore this part.)

Sample Input and Output

Sample Input #1

7
1 2 0
1 6 0
1 6 1
3 5
2 2
1 3 0
3 123456789012

Sample Output #1

2
1 2
3 3
2
3 3
4 3

Sample Input #2

5
1 1 0
1 1 0
1 1 0
3 2
1 1 0

Sample Output #2

2
1 1
2 1

Sample Input #3

4
1 19 1
3 10
3 10
3 10

Sample Output #3

1
1 10
1
1 9
0

Notes/Hints

Data Range

Subtask Points Special Conditions
0 0 Examples
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 conditions

For $100\%$ of the data:

  • $1 \le q \le 200000$
  • For all join operations, $1 \le s \le 200000, 0 \le w \le 1$.
  • For all leave operations, ensure all $i$ are 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.
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
7 1 2 0 1 6 0 1 6 1 3 5 2 2 1 3 0 3 123456789012
样例输出
2 1 2 3 3 2 3 3 4 3