#abc217e. E - Sorting Queries

E - Sorting Queries

Score : 500500 points

问题描述

我们有一个空的序列 AA。你将收到 QQ 个查询,这些查询需要按照给定的顺序进行处理。每个查询属于以下三种类型之一:

  • 1 x:将 xx 添加到 AA 的末尾。
  • 2:打印 AA 开头的元素。然后,删除该元素。保证在给出此查询时,AA 不会为空。
  • 3:将 AA 按升序排列。

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

Problem Statement

We have an empty sequence AA. You will be given QQ queries, which should be processed in the order they are given. Each query is of one of the three kinds below:

  • 1 x : Append xx to the end of AA.
  • 2 : Print the element at the beginning of AA. Then, delete that element. It is guaranteed that AA will not empty when this query is given.
  • 3 : Sort AA in ascending order.

Constraints

  • 1Q2×1051 \leq Q \leq 2 \times 10^5
  • 0x1090 \leq x \leq 10^9
  • AA will not be empty when a query 2 is given.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

QQ

query1\mathrm{query} 1

query2\mathrm{query} 2

\vdots

queryQ\mathrm{query} Q

The ii-th query, queryi\mathrm{query} i, begins with the kind of query cic_i (11, 22, or 33). If ci=1c_i = 1, the line additionally has an integer xx.

In other words, each query is in one of the three formats below.

11 xx

22

33

Output

Print qq lines, where qq is the number of queries with ci=2c_i = 2.
The jj-th line (1jq)(1 \leq j \leq q) should contain the response for the jj-th such query.

Sample Input 1

8
1 4
1 3
1 2
1 1
3
2
1 0
2

Sample Output 1

1
2

The ii-th line below shows the contents of AA after the ii-th query is processed in Sample Input 11.

  • (4)(4)
  • (4,3)(4, 3)
  • (4,3,2)(4, 3, 2)
  • (4,3,2,1)(4, 3, 2, 1)
  • (1,2,3,4)(1, 2, 3, 4)
  • (2,3,4)(2, 3, 4)
  • (2,3,4,0)(2, 3, 4, 0)
  • (3,4,0)(3, 4, 0)

Sample Input 2

9
1 5
1 5
1 3
2
3
2
1 6
3
2

Sample Output 2

5
3
5

The ii-th line below shows the contents of AA after the ii-th query is processed in Sample Input 22.

  • (5)(5)
  • (5,5)(5, 5)
  • (5,5,3)(5, 5, 3)
  • (5,3)(5, 3)
  • (3,5)(3, 5)
  • (5)(5)
  • (5,6)(5, 6)
  • (5,6)(5, 6)
  • (6)(6)

update @ 2024/3/10 09:37:05