Problem: I - The J-th Number

Problem Statement

You are given N empty arrays, t_1, ..., t_n. At first, you execute M queries as follows.

* add a value v to array t_i (a \leq i \leq b)



Next, you process Q following output queries.

* output the j-th number of the sequence sorted all values in t_i (x \leq i \leq y)



Input

The dataset is formatted as follows.


N M Q
a_1 b_1 v_1
...
a_M b_M v_M
x_1 y_1 j_1
...
x_Q y_Q j_Q


The first line contains three integers N (1 \leq N \leq 10^9), M (1 \leq M \leq 10^5) and Q (1 \leq Q \leq 10^5). Each of the following M lines consists of three integers a_i, b_i and v_i (1 \leq a_i \leq b_i \leq N, 1 \leq v_i \leq 10^9). Finally the following Q lines give the list of output queries, each of these lines consists of three integers x_i, y_i and j_i (1 \leq x_i \leq y_i \leq N, 1 \leq j_i \leq Σ_{x_i \leq k \leq y_i} |t_k|).

Output

For each output query, print in a line the j-th number.

Sample Input 1


5 4 1
1 5 1
1 1 3
4 5 1
3 4 2
1 3 4


Output for the Sample Input 1


2


After the M-th query is executed, each t_i is as follows:


[1,3], [1], [1,2], [1,1,2], [1,1]


The sequence sorted values in t_1, t_2 and t_3 is [1,1,1,2,3]. In the sequence, the 4-th number is 2.

Sample Input 2


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


Output for the Sample Input 2


11
11
33
44






Example

Input

5 4 1
1 5 1
1 1 3
4 5 1
3 4 2
1 3 4


Output

2

Solution (in CPP):

Solution:
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

using Int = long long;

template <typename T,typename E>
struct SegmentTree{
    using F = function<T(T,T)>;
    using G = function<T(T,E)>;
    using H = function<E(E,E)>;
    int n,height;
    F f;
    G g;
    H h;
    T ti;
    E ei;
    vector<T> dat;
    vector<E> laz;
    SegmentTree(F f,G g,H h,T ti,E ei):
    f(f),g(g),h(h),ti(ti),ei(ei){}
    
    void init(int n_){
        n=1;height=0;
        while(n<n_) n<<=1,height++;
        dat.assign(2*n,ti);
        laz.assign(2*n,ei);
    }
    void build(const vector<T> &v){
        int n_=v.size();
        init(n_);
        for(int i=0;i<n_;i++) dat[n+i]=v[i];
        for(int i=n-1;i;i--)
            dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
    }
    inline T reflect(int k){
        return laz[k]==ei?dat[k]:g(dat[k],laz[k]);
    }
    inline void eval(int k){
        if(laz[k]==ei) return;
        laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);
        laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);
        dat[k]=reflect(k);
        laz[k]=ei;
    }
    inline void thrust(int k){
        for(int i=height;i;i--) eval(k>>i);
    }
    inline void recalc(int k){
        while(k>>=1)
            dat[k]=f(reflect((k<<1)|0),reflect((k<<1)|1));
    }
    void update(int a,int b,E x){
        thrust(a+=n);
        thrust(b+=n-1);
        for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
            if(l&1) laz[l]=h(laz[l],x),l++;
            if(r&1) --r,laz[r]=h(laz[r],x);
        }
        recalc(a);
        recalc(b);
    }
    void set_val(int a,T x){
        thrust(a+=n);
        dat[a]=x;laz[a]=ei;
        recalc(a);
    }
    T query(int a,int b){
        thrust(a+=n);
        thrust(b+=n-1);
        T vl=ti,vr=ti;
        for(int l=a,r=b+1;l<r;l>>=1,r>>=1) {
            if(l&1) vl=f(vl,reflect(l++));
            if(r&1) vr=f(reflect(--r),vr);
        }
        return f(vl,vr);
    }
};


int main(){
    map<ll,ll> M;
    ll n,m,q;
    cin>>n>>m>>q;
    vector<pair<ll,pll>> A(m);
    for(auto &I:A){cin>>I.S.F>>I.S.S>>I.F; I.S.F--; M[I.S.F]=M[I.S.S]=-1;}
    sort(A.begin(),A.end());
    vector<pair<ll,pll>> B(q);
    for(auto &I:B){cin>>I.S.F>>I.S.S>>I.F; I.S.F--; M[I.S.F]=M[I.S.S]=-1;}
    M[m]=-1;
    ll num=0;
    ll left=0;
    vector<pll> K(M.size(),{0,0});
    for(auto I=M.begin();I!=M.end();++I){
        I->second=num;
        if(num!=0){K[num-1].S=I->first-left;}
        left=I->first;
        num++;
    }
    for(auto &I:A){I.S.F=M[I.S.F]; I.S.S=M[I.S.S];}
    for(auto &I:B){I.S.F=M[I.S.F]; I.S.S=M[I.S.S];}
    vector<pll> C(q);
    for(auto &I:C){I.F=0; I.S=m;}
    const ll D=25;
    vector<pll> Q(q);
    
    using P = pair<Int, Int>;
    auto f=[](P a,P b){return P(a.first+b.first,a.second+b.second);};
    auto g=[](P a,Int b){return P(a.first+b*a.second,a.second);};
    auto h=[](Int a,Int b){return a+b;};
    
    SegmentTree<P,Int> T(f,g,h,P(0,0),0);
    T.build(K);
    
    for(int time=0;time<D;time++){
        for(int i=0;i<q;i++){Q[i]={C[i].F+(C[i].S-C[i].F)/2,i};}
        sort(Q.begin(),Q.end());
        ll l=0;
        for(int i=0;i<m;i++){
            while(l<q && Q[l].F==i){
                ll cnt=T.query(B[Q[l].S].S.F,B[Q[l].S].S.S).F;
                if(cnt<B[Q[l].S].F){
                    C[Q[l].S].F=i;
                }
                else{
                    C[Q[l].S].S=i;
                }
                l++;
            }
            T.update(A[i].S.F,A[i].S.S,1);
        }
        for(auto &I:A){T.update(I.S.F,I.S.S,-1);}
    }
    for(auto &I:C){
        assert(I.F+1==I.S);
        cout<<A[I.F].F<<endl;
    }
    
    
    return 0;
}