Subtract if Greater!
Time limit5sMemory limit512 MB
Maintain a multiset under queries that ask for the k-th smallest element and queries that subtract x from every element greater than x, then report each k-th smallest.
- Level
Hard8 of 10
- Topics
- Segment tree, Binary search, Sorting, Implementation
- Solved
- No attempts yet
Problem
Consider a multiset consisting of elements: .
We define two types of operations that can be performed on this multiset:
- Given , print the number that would be the -th element if we sort the multiset in non-decreasing order.
- Given , subtract from all elements of that are strictly greater than .
Perform the given operations in the given order and output the results of all operations of the first type.
Input
The first line contains two integers and : the size of the multiset and the number of queries (, ).
The second line contains integers (): the elements of .
Each of the next lines describes a single operation. An operation is given as two integers and : the type and the parameter of the operation. It is guaranteed that . If , then . If , then .
It is guaranteed that there is at least one operation of type .
The elements of are given in arbitrary order.
Output
For each operation of the first type, output the -th element in non-decreasing order. Separate the answers with line breaks.