#abc212d. D - Querying Multiset

D - Querying Multiset

Score : 400400 points

问题描述

Takahashi有许多空白的球和一个袋子。最初,袋子是空的。Takahashi将执行QQ次操作,每次操作属于以下三种类型之一。

  • 类型 11: 在一个空白球上写入整数XiX_i,然后将其放入袋子中。
  • 类型 22: 对于袋子中的每个球,用该球上所写的整数加上XiX_i来替换它。
  • 类型 33: 拿起袋子里整数最小的那个球(如果有多个这样的球,取出其中一个)。记录这个球上所写的整数并将其丢弃。

对于每个1iQ1\leq i\leq Q,已知第ii次操作的类型PiP_i以及如果该操作是类型1122时的XiX_i值。按照顺序打印出类型33操作所记录的整数。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Takahashi has many balls, on which nothing is written, and one bag. Initially, the bag is empty. Takahashi will do QQ operations, each of which is of one of the following three types.

  • Type 11: Write an integer XiX_i on a blank ball and put it in the bag.
  • Type 22: For each ball in the bag, replace the integer written on it with that integer plus XiX_i.
  • Type 33: Pick up the ball with the smallest integer in the bag (if there are multiple such balls, pick up one of them). Record the integer written on this ball and throw it away.

For each 1iQ1\leq i\leq Q, you are given the type PiP_i of the ii-th operation and the value of XiX_i if the operation is of Type 11 or 22. Print the integers recorded in the operations of Type 33 in order.

Constraints

  • 1Q2×1051 \leq Q \leq 2\times 10^5
  • 1Pi31 \leq P_i \leq 3
  • 1Xi1091 \leq X_i \leq 10^9
  • All values in input are integers.
  • There is one or more ii such that Pi=3P_i=3.
  • If Pi=3P_i=3, the bag contains at least one ball just before the ii-th operation.

Input

Input is given from Standard Input in the following format:

QQ

query1query_1

query2query_2

::

queryQquery_Q

Each queryiquery_i in the 22-nd through (Q+1)(Q+1)-th lines is in the following format:

11 XiX_i

22 XiX_i

33

The first number in each line is 1Pi31\leq P_i\leq 3, representing the type of the operation. If Pi=1P_i=1 or Pi=2P_i=2, it is followed by a space, and then by XiX_i.

Output

For each operation with Pi=3P_i=3 among the QQ operations, print the recorded integer in its own line.

Sample Input 1

5
1 3
1 5
3
2 2
3

Sample Output 1

3
7

Takahashi will do the following operations.

  • Write 33 on a ball and put it in the bag.
  • Write 55 on a ball and put it in the bag.
  • The bag now contains a ball with 33 and another with 55. Pick up the ball with the smaller of them, or 33. Record 33 and throw it away.
  • The bag now contains just a ball with 55. Replace this integer with 5+2=75+2=7.
  • The bag now contains just a ball with 77. Pick up this ball, record 77, and throw it away.

Therefore, we should print 33 and 77, in the order they are recorded.

Sample Input 2

6
1 1000000000
2 1000000000
2 1000000000
2 1000000000
2 1000000000
3

Sample Output 2

5000000000

Note that the outputs may not fit into a 3232-bit integer.

update @ 2024/3/10 09:27:25