#P1801. 黑匣子

    ID: 756 远端评测题 500ms 500MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>线段树平衡树二叉堆NOI 导刊O2优化

黑匣子

Description

Black Box is a primitive database. It can store an integer array and a special variable ii. Initially, the Black Box is empty and i=0i = 0. This Black Box needs to process a sequence of commands.

There are only two types of commands:

  • ADD(x): insert element xx into the Black Box;
  • GET: increase ii by 11, then output the ii-th smallest number in the Black Box.

Remember: the ii-th smallest number is the ii-th element in the Black Box when its numbers are sorted in ascending order.

Let’s demonstrate a sequence of 11 commands (as shown in the table below).

No. Operation ii Database Output
1 ADD(3) 00 33 /
2 GET 11 33
3 ADD(1) 1,31,3 /
4 GET 22 33
5 ADD(-4) 4,1,3-4,1,3 /
6 ADD(2) 4,1,2,3-4,1,2,3
7 ADD(8) 4,1,2,3,8-4,1,2,3,8
8 ADD(-1000) 1000,4,1,2,3,8-1000,-4,1,2,3,8
9 GET 33 11
10 44 22
11 ADD(2) 1000,4,1,2,2,3,8-1000,-4,1,2,2,3,8 /

Now you are asked to determine the outputs for a given command sequence. There are mm ADD commands and nn GET commands. The command sequence is represented by two integer arrays:

  1. a1,a2,,ama_1, a_2, \cdots, a_m: the sequence of elements to be inserted into the Black Box. For example, in the above example a=[3,1,4,2,8,1000,2]a = [3, 1, -4, 2, 8, -1000, 2].
  2. u1,u2,,unu_1, u_2, \cdots, u_n: after the uiu_i-th element has been inserted into the Black Box, a GET command appears. For example, in the above example u=[1,2,6,6]u = [1, 2, 6, 6]. You do not need to validate the input.

Input Format

  • The first line contains two integers mm and nn, the number of elements and the number of GET commands.
  • The second line contains mm integers. From left to right, the ii-th integer is aia_i, separated by spaces.
  • The third line contains nn integers. From left to right, the ii-th integer is uiu_i, separated by spaces.

Output Format

Output the sequence produced by the Black Box according to the command sequence, one number per line.

7 4
3 1 -4 2 8 -1000 2
1 2 6 6

3
3
1
2

Hint

Constraints

  • For 30%30\% of the testdata, 1n,m1041 \leq n, m \leq 10^{4}.
  • For 50%50\% of the testdata, 1n,m1051 \leq n, m \leq 10^{5}.
  • For 100%100\% of the testdata, 1n,m2×1051 \leq n, m \leq 2 \times 10^{5}, ai2×109|a_i| \leq 2 \times 10^{9}, and the sequence uu is non-decreasing.

Translated by ChatGPT 5