fork download
  1. #include <bits/stdc++.h>
  2. #include <iostream>
  3. #include <set>
  4. #include <vector>
  5. #include <algorithm>
  6. #include <string>
  7. #include <cmath>
  8. using namespace std;
  9. #define ll long long
  10. #define _CRT_SECURE_NO_WARNINGS
  11. #define endl '\n'
  12. #define time clock_t tStart = clock();
  13. #define show printf("Time taken: %.6fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
  14. #define loop(a,b) for(int i=a;i<=b;++i)
  15. #define count_1(n) __builtin_popcountll(n)
  16. #define pb push_back
  17. #define F first
  18. #define S second
  19. #define mp make_pair
  20. #define MOD 1000000007
  21. #define itoc(c) ((char)(((int)'0')+c))
  22. #define vi vector<int>
  23. #define vll vector<ll>
  24. #define pll pair<ll,ll>
  25. #define pii pair<int,int>
  26. #define all(v) v.begin(),v.end()
  27. #define mid(s,e) (s+(e-s)/2)
  28. #define tcase() ll t,n; cin>>t;n=t; while(t--)
  29. #define eb emplace_back
  30. #define ull unsigned long long
  31. #define minimize INT_MAX
  32. #define maximize INT_MIN
  33. #define dsort(a) sort(a.begin(), a.end(), greater<int>())
  34. #define fr(i,n) for(ll i=0; i<n; i++)
  35. #define fr1(i,n) for(ll i=1; i<=n; i++)
  36. #define vp(n) vector<pair<int,int>>v(n);
  37.  
  38.  
  39. void fast(){
  40. ios_base::sync_with_stdio(0);
  41. cin.tie(0);
  42. cout.tie(0);
  43. //cout.setf(ios::fixed);
  44. //cout.precision(20);
  45. #ifndef _offline
  46. // freopen("mex.in", "r", stdin);
  47. //freopen("output.txt", "w", stdout);
  48. #endif
  49. }
  50.  
  51. void HaXn() {
  52. int n,m;
  53. cin >> n >>m;
  54.  
  55. vector<pair<ll,ll>>v(n);
  56. fr(i,n){
  57. cin >> v[i].F >> v[i].S;
  58. if (v[i].F >v[i].S){
  59. swap(v[i].F, v[i].S);
  60. }
  61. }
  62. sort(v.begin(),v.end());
  63. ll start = v[0].F;
  64. ll end = v[0].S;
  65. vector<pair<ll,ll>>ans;
  66. for (int i =1; i<n; i++){
  67. if (v[i].F > end){
  68. ans.push_back({start,end});
  69. start = v[i].F;
  70. end = v[i].S;
  71. }else{
  72. end = max(end,v[i].S);
  73. }
  74. }
  75. ans.push_back({start,end});
  76.  
  77. int t; cin >> t;
  78. while (t--){
  79. int l ,r; cin >>l >>r;
  80. if (l>r) swap(l,r);
  81. bool check = false;
  82. for (int i =0; i<ans.size(); i++){
  83. if (l>=ans[i].F && r<=ans[i].S){
  84. check = true;
  85. }
  86. }
  87. if (check) cout << "YES" << endl;
  88. else cout<<"NO" << endl;
  89. }
  90.  
  91. }
  92.  
  93. int main() {
  94. fast();
  95. HaXn();
  96. }
Success #stdin #stdout 0s 5288KB
stdin
5 20
1 2
2 3
5 9
7 10
15 20
9
1 2
1 3
2 3
1 4
5 4
5 10
6 9
16 19
5 16
stdout
YES
YES
YES
NO
NO
YES
YES
YES
NO