#abc241d. D - Sequence Query

D - Sequence Query

Score : 400400 points

问题描述

我们有一个空的序列 AA
给定 QQ 个查询,按照顺序处理它们。
每个查询属于以下三种类型之一。

  • 1 x :将 xx 插入到 AA 中。

  • 2 x k :在 AA 中小于等于 xx 的元素中,输出第 kk 大的值。 (kk 不超过 5\bf{5}
    如果 AA 中小于等于 xx 的元素少于 kk 个,则输出 -1

  • 3 x k :在 AA 中大于等于 xx 的元素中,输出第 kk 小的值。 (kk 不超过 5\bf{5}
    如果 AA 中大于等于 xx 的元素少于 kk 个,则输出 -1

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

Problem Statement

We have an empty sequence AA.
Given QQ queries, process them in order.
Each query is of one of the following three types.

  • 1 x : Insert xx to AA.

  • 2 x k : Among the elements of AA that are less than or equal to xx, print the kk-th largest value. (kk is no more than 5\bf{5})
    If there are less than kk elements of AA that are less than or equal to xx, then print -1.

  • 3 x k : Among the elements of AA that are greater than or equal to xx, print the kk-th smallest value. (kk is no more than 5\bf{5})
    If there are less than kk elements of AA that are greater than or equal to xx, then print -1.

Constraints

  • 1Q2×1051\leq Q \leq 2\times 10^5
  • 1x10181\leq x\leq 10^{18}
  • 1k51\leq k\leq 5
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

QQ

query1\text{query}_1

query2\text{query}_2

\vdots

queryQ\text{query}_Q

In the ii-th query queryi\text{query}_i, the type of query cic_i (which is either 1,21, 2, or 33) is given first.

If ci=1c_i=1, then xx is additionally given; if ci=2,3c_i=2, 3, then xx and kk are additionally given.

In other words, each query is given in one of the following three formats:

11 xx

22 xx kk

33 xx kk

Output

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

Sample Input 1

11
1 20
1 10
1 30
1 20
3 15 1
3 15 2
3 15 3
3 15 4
2 100 5
1 1
2 100 5

Sample Output 1

20
20
30
-1
-1
1

After query1,2,3,4\text{query}_{1,2,3,4} have been processed, we have A=(20,10,30,20)A=(20,10,30,20).

For query5,6,7\text{query}_{5,6,7}, the elements of AA greater than or equal to 1515 are (20,30,20)(20,30,20).
The 11-st smallest value of them is 2020; the 22-nd is 2020; the 33-rd is 3030.

update @ 2024/3/10 10:23:31

}