# Untitled

unknown
plain_text
a month ago
1.7 kB
3
Indexable
Never
```#include <bits/stdc++.h>
using namespace std ;
#define int long long
#define For(n) for(int i = 0; i < n; i++)
#define endl '\n'
#define ld long double
bool cmp(pair<int,int>p1,pair<int,int>p2){
if(p1.first<p2.first) return 1;
else if(p1.first>p2.first) return 0;
else return p1.second<p2.second;
}
pair<int,int> mergepaires(pair<int,int>p1,pair<int,int>p2){
int st = min(p1.first,p2.first),end = max(p2.second,p1.second);
return {st,end};
}
void solve (){
vector<pair<int,int>> v;
int n,m,q;cin>>n>>m;
pair<int,int> arr[n];
For(n)cin>>arr[i].first>>arr[i].second;
sort(arr,arr+n,cmp);
// for(auto it:arr) cout <<it.first<<" "<<it.second<<endl;
pair<int,int> tmp = arr[0];
for(int i =1;i<n;i++){
if(tmp.second >= arr[i].first) tmp = mergepaires(tmp,arr[i]);
else {
v.push_back(tmp);
tmp = arr[i];
}
}
v.push_back(tmp);
// for(auto it:v) cout <<it.first<<" "<<it.second<<endl;
cin>>q;
while (q--){
int l,r;cin>>l>>r;
if(r<l) swap(r,l);
int st=0,end=v.size()-1;
bool b = false;
if(l==r)b=true;
while (st<=end){
int mid = (st+end)/2;
if(l>=v[mid].first && r<= v[mid].second){
b = true;
break;
}
else if (r < v[mid].first)end = mid-1 ;
else st = mid+1;
}
if(b)cout << "YES" <<endl;
else    cout <<"NO"<<endl;
}
}
signed main ()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t =1;
// cin>>t;
while (t--){
solve();
}
}```