lina_os

Untitled

Apr 2nd, 2025 (edited)
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  8. ll n,m;
  9. cin >> n >> m;
  10. vector<pair<int,int>>vv;
  11. while (n--) {
  12. int l,r;
  13. cin >> l >> r;
  14. vv.push_back({l,r});
  15. }
  16. sort(vv.begin(), vv.end());
  17. vector<pair<int,int>>v;
  18. for (auto &i:vv) {
  19. if (v.empty() || v.back().second<i.first) {
  20. v.push_back(i);
  21. }
  22. else v.back().second=max(i.second,v.back().second);
  23. }
  24. // for (int i=0; i<v.size(); i++) {
  25. // cout << v[i].first << " " << v[i].second << endl;
  26. // }
  27. int q;
  28. cin >> q;
  29. while (q--) {
  30. int u,x;
  31. cin >> u >> x;
  32. if (x<u) swap(x,u);
  33. int f=0;
  34. for (auto i:v) {
  35. if (u>=i.first && x<=i.second) {
  36. cout << "YES" << endl;
  37. f=1;
  38. break;
  39. }
  40. }
  41. if (!f) cout << "NO" << endl;
  42. }
  43. return 0;
  44. }
  45.  
  46.  
Advertisement
Add Comment
Please, Sign In to add comment