#include #include using namespace std; using namespace atcoder; void solve(){ int n, k, q; cin >> n >> k >> q; vector L(k), R(k), C(k), I(q); vector H(k), X(q); for(int i = 0; i < k; i++){ cin >> L[i] >> R[i] >> C[i] >> H[i]; } for(int i = 0; i < q; i++){ cin >> I[i] >> X[i]; } fenwick_tree bit(n + 1); for(int i = 0; i < k; i++){ bit.add(L[i] - 1, H[i]); bit.add(R[i], -H[i]); } vector ans(q); vector LL, RR; vector> ind(1, vector()); LL.push_back(0); RR.push_back(k); for(int i = 0; i < q; i++){ long long h = bit.sum(0, I[i]); if(h < X[i]) ans[i] = -1; else ind[0].push_back(i); } while(!ind.empty()){ vector nLL, nRR; vector> nind; int bj = 0; int size = ind.size(); fenwick_tree bit(n + 1); for(int i = 0; i < size; i++){ if(RR[i] - LL[i] <= 1){ for(auto j:ind[i]){ ans[j] = C[RR[i] - 1]; } continue; } int mid = (LL[i] + RR[i]) / 2; for(int j = bj; j < mid; j++){ bit.add(L[j] - 1, H[j]); bit.add(R[j], -H[j]); } vector bef, aft; for(auto j:ind[i]){ long long h = bit.sum(0, I[j]); if(h < X[j]) aft.push_back(j); else bef.push_back(j); } if(!bef.empty()){ nLL.push_back(LL[i]); nRR.push_back(mid); nind.push_back(bef); } if(!aft.empty()){ nLL.push_back(mid); nRR.push_back(RR[i]); nind.push_back(aft); } bj = mid; } LL = nLL; RR = nRR; ind = nind; } for(auto a:ans){ cout << a << "\n"; } } int main(){ cin.tie(0)->sync_with_stdio(0); int t; t = 1; // cin >> t; while(t--) solve(); }