#include #include #include #include #include using namespace std; long op(long a,long b){return a+b;} long e(){return 0L;} int N,Q; int A[2<<17],T[2<<17],L[2<<17],R[2<<17]; long ans[2<<17]; int main() { cin>>N; vector >AT(N); for(int i=0;i>A[i]>>T[i]; AT[i]=make_pair(T[i],i); } sort(AT.begin(),AT.end()); cin>>Q; vector >LR(Q); for(int i=0;i>D>>L[i]>>R[i]; L[i]--; LR[i]=make_pair(D,i); } sort(LR.begin(),LR.end()); atcoder::segtreeprv(vector(A,A+N)),cur(N),cnt(N); priority_queue >queue; int ati=0; for(pairq:LR) { while(ati