#P1801. 黑匣子
黑匣子
Description
Black Box is a primitive database. It can store an integer array and a special variable . Initially, the Black Box is empty and . This Black Box needs to process a sequence of commands.
There are only two types of commands:
ADD(x): insert element into the Black Box;GET: increase by , then output the -th smallest number in the Black Box.
Remember: the -th smallest number is the -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 | Database | Output | |
|---|---|---|---|---|
| 1 | ADD(3) |
/ | ||
| 2 | GET |
|||
| 3 | ADD(1) |
/ | ||
| 4 | GET |
|||
| 5 | ADD(-4) |
/ | ||
| 6 | ADD(2) |
|||
| 7 | ADD(8) |
|||
| 8 | ADD(-1000) |
|||
| 9 | GET |
|||
| 10 | ||||
| 11 | ADD(2) |
/ |
Now you are asked to determine the outputs for a given command sequence. There are ADD commands and GET commands. The command sequence is represented by two integer arrays:
- : the sequence of elements to be inserted into the Black Box. For example, in the above example .
- : after the -th element has been inserted into the Black Box, a
GETcommand appears. For example, in the above example . You do not need to validate the input.
Input Format
- The first line contains two integers and , the number of elements and the number of
GETcommands. - The second line contains integers. From left to right, the -th integer is , separated by spaces.
- The third line contains integers. From left to right, the -th integer is , 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 of the testdata, .
- For of the testdata, .
- For of the testdata, , , and the sequence is non-decreasing.
Translated by ChatGPT 5
京公网安备 11011102002149号