pb_jiang

ABC457E

May 10th, 2026
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.14 KB | None | 0 0
  1. // Problem: E - Crossing Table Cloth
  2. // Contest: AtCoder - Polaris.AI Programming Contest 2026(AtCoder Beginner Contest 457)
  3. // URL: https://atcoder.jp/contests/abc457/tasks/abc457_e
  4. // Memory Limit: 1024 MB
  5. // Time Limit: 2500 ms
  6. //
  7. // Powered by CP Editor (https://cpeditor.org)
  8.  
  9. #include <assert.h>
  10. #include <bits/stdc++.h>
  11. using namespace std;
  12. #ifndef __DEBUG__
  13. #define dbg(...) 42
  14. #endif
  15. template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
  16.  
  17. namespace rngs = std::ranges;
  18. using ll = long long;
  19. using a2l = array<ll, 2>;
  20. using vl = vector<ll>;
  21.  
  22. void solve()
  23. {
  24.     ll n, m, q;
  25.     cin >> n >> m;
  26.     vector<a2l> rs(m);
  27.     map<a2l, ll> cnt;
  28.     for (auto &x : rs)
  29.         cin >> x[0] >> x[1], cnt[x] += 1;
  30.     rngs::sort(rs);
  31.  
  32.     cin >> q;
  33.     using a3l = array<ll, 3>;
  34.     vector<a3l> qs(q);
  35.     for (auto &x : qs)
  36.         cin >> x[0] >> x[1];
  37.     for (ll i = 0; i < q; ++i)
  38.         qs[i][2] = i;
  39.  
  40.     rngs::sort(qs);
  41.     vl ans(q);
  42.     vector<vl> lb(n + 1), rb(n + 1);
  43.     for (auto [x, y] : rs) {
  44.         dbg(x, y);
  45.         assert(x >= 1 && x <= n);
  46.         assert(y >= 1 && y <= n);
  47.         lb[y].push_back(x), rb[x].push_back(y);
  48.     }
  49.  
  50.     for (auto &x : lb)
  51.         rngs::sort(x);
  52.     for (auto &x : rb)
  53.         rngs::sort(x);
  54.  
  55.     for (auto [x, y, id] : qs) {
  56.         if (cnt.count({x, y}) && cnt[{x, y}] >= 2) {
  57.             ans[id] = 1;
  58.             continue;
  59.         }
  60.  
  61.         if (rb[x].empty())
  62.             continue;
  63.         auto it = upper_bound(rb[x].begin(), rb[x].end(), y - 1) - rb[x].begin();
  64.         if (it == 0)
  65.             continue;
  66.         ll v = rb[x][it - 1];
  67.  
  68.         if (lb[y].empty())
  69.             continue;
  70.         auto it2 = upper_bound(lb[y].begin(), lb[y].end(), x) - lb[y].begin();
  71.  
  72.         if (it2 != lb[y].size() && lb[y][it2] <= v)
  73.             ans[id] = 1, dbg(lb[y][it2], v);
  74.     }
  75.  
  76.     for (auto x : ans)
  77.         cout << (x ? "Yes" : "No") << endl;
  78. }
  79.  
  80. int main(int argc, char **argv)
  81. {
  82.     std::ios::sync_with_stdio(false);
  83.     std::cin.tie(nullptr);
  84.  
  85.     ll t = 1;
  86.     // cin >> t;
  87.     while (t--)
  88.         solve();
  89.  
  90.     return 0;
  91. };
  92.  
Advertisement
Add Comment
Please, Sign In to add comment