The operations that are performed in a data structure can be categorized into two types: query and update. A query operation usually answers some specific questions about the stored data. An update usually adds data or changes the state of data in the structure. For example, adding an element or deleting the top element of a stack are update operations. While, accessing the top element is a query operation.
In this problem, you are asked to design a data structure. This data structure will support two operations:
Update(A)
: Add an integer to the collection.
Query(B)
: Return the -th smallest number from the collection.
For example, if the existing numbers in the collection are , then performing Query(2)
will return 3. If we perform Update(2)
on the existing collection, then Query(6)
will return 7.
You will have to perform operations of this data structure. Each update operation will be immediately followed by a valid query operation. Please see the samples and explanation for further understanding.
The first line contains an integer (), the number of updates you have to perform for this dataset. You will also have to perform query operations as well.
Next line contains integers (), where each indicates the number to be added for the -th update operation.
Then follows another line with numbers (). For each , you will have to print the -th integer in the collection after the -th update operation.
For each query operation, print the answer on a line by itself.
Input | Output |
---|---|
6 1 4 3 7 5 2 1 2 2 4 3 6 | 1 4 3 7 4 7 |
In the first sample, the following are the first few instructions that are performed in order:
Similarly, the remaining instructions will be performed in the following order: |
Input | Output |
---|---|
7 1 4 3 10 15 20 25 1 2 2 4 5 6 7 | 1 4 3 10 15 20 25 |