Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- ll n,m;
- cin >> n >> m;
- vector<pair<int,int>>v;
- while (n--) {
- int l,r;
- cin >> l >> r;
- int f=0;
- for (int i=0; i<v.size(); i++) {
- if (max(v[i].first,l) <= min(v[i].second,r)) {
- f=1;
- v[i].first=min(v[i].first, l);
- v[i].second=max(v[i].second, r);
- for (int j=0; j<v.size(); j++) {
- if (max(v[i].first,v[j].first) <= min(v[i].second,v[j].second) && j!=i) {
- v[i].first=min(v[i].first, v[j].first);
- v[i].second=max(v[i].second, v[j].second);
- v.erase(v.begin()+j);
- }
- }
- break;
- }
- }
- if (!f) v.insert(v.end(), {l,r});
- }
- // for (int i=0; i<v.size(); i++) {
- // cout << v[i].first << " " << v[i].second << endl;
- // }
- int q;
- cin >> q;
- while (q--) {
- int u,x;
- cin >> u >> x;
- if (x<u) swap(x,u);
- int f=0;
- for (auto i:v) {
- if (u>=i.first && x<=i.second) {
- cout << "YES" << endl;
- f=1;
- break;
- }
- }
- if (!f) cout << "NO" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment