The j-th Number
Time limit10sMemory limit512 MB
After copying each insert value into every array of its interval, each query asks for the j-th smallest value collected from an interval of arrays.
- Level
Hard8 of 10
- Topics
- Binary search, Segment tree, Sorting, Intervals
- Solved
- No attempts yet
Problem
You have empty arrays . First you run insert operations in the given order.
- for every with , put one copy of the value into the array
After every insertion is done, you answer queries.
- collect the values of every array with , sort them in non-decreasing order, and print the -th value of that sequence
The same value can enter one array several times, and duplicates stay in the sorted sequence.
Input
The input has the following format.
N M Q
a1 b1 v1
...
aM bM vM
x1 y1 j1
...
xQ yQ jQ
The first line contains three integers , and (, , ).
Each of the next lines describes one insert operation with three integers , and (, ).
Each of the following lines describes one query with three integers , and (, ), where is the number of values stored in the array .
Output
For each query, print the -th value on its own line.
Note
In the first example, the arrays look like this once every insert operation is done.
[1,3], [1], [1,2], [1,1,2], [1,1]
Collecting the values of , and and sorting them gives , and the 4th value of that sequence is 2.