This page is still under construction.

Parts of this page are still being built. What you see may change.

The j-th Number

Time limit10sMemory limit512 MB

Summary
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 NN empty arrays t1,t2,…,tNt_1, t_2, \dots, t_N. First you run MM insert operations in the given order.

  • for every ii with a≤i≤ba \le i \le b, put one copy of the value vv into the array tit_i

After every insertion is done, you answer QQ queries.

  • collect the values of every array tit_i with x≤i≤yx \le i \le y, sort them in non-decreasing order, and print the jj-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 NN, MM and QQ (1≤N≤1091 \le N \le 10^9, 1≤M≤1051 \le M \le 10^5, 1≤Q≤1051 \le Q \le 10^5).

Each of the next MM lines describes one insert operation with three integers aia_i, bib_i and viv_i (1≤ai≤bi≤N1 \le a_i \le b_i \le N, 1≤vi≤1091 \le v_i \le 10^9).

Each of the following QQ lines describes one query with three integers xix_i, yiy_i and jij_i (1≤xi≤yi≤N1 \le x_i \le y_i \le N, 1≤ji≤∑xi≤k≤yi∣tk∣1 \le j_i \le \sum_{x_i \le k \le y_i} |t_k|), where ∣tk∣|t_k| is the number of values stored in the array tkt_k.

Output

For each query, print the jj-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 t1t_1, t2t_2 and t3t_3 and sorting them gives [1,1,1,2,3][1,1,1,2,3], and the 4th value of that sequence is 2.

Examples2

  1. Example 1

    Input
    5 4 1
    1 5 1
    1 1 3
    4 5 1
    3 4 2
    1 3 4
    
    Expected output
    2
    
  2. Example 2

    Input
    10 4 4
    1 4 11
    2 3 22
    6 9 33
    8 9 44
    1 1 1
    4 5 1
    4 6 2
    1 10 12
    
    Expected output
    11
    11
    33
    44