Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Problem: E - Crossing Table Cloth
- // Contest: AtCoder - Polaris.AI Programming Contest 2026(AtCoder Beginner Contest 457)
- // URL: https://atcoder.jp/contests/abc457/tasks/abc457_e
- // Memory Limit: 1024 MB
- // Time Limit: 2500 ms
- //
- // Powered by CP Editor (https://cpeditor.org)
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- #ifndef __DEBUG__
- #define dbg(...) 42
- #endif
- template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
- namespace rngs = std::ranges;
- using ll = long long;
- using a2l = array<ll, 2>;
- using vl = vector<ll>;
- void solve()
- {
- ll n, m, q;
- cin >> n >> m;
- vector<a2l> rs(m);
- map<a2l, ll> cnt;
- for (auto &x : rs)
- cin >> x[0] >> x[1], cnt[x] += 1;
- rngs::sort(rs);
- cin >> q;
- using a3l = array<ll, 3>;
- vector<a3l> qs(q);
- for (auto &x : qs)
- cin >> x[0] >> x[1];
- for (ll i = 0; i < q; ++i)
- qs[i][2] = i;
- rngs::sort(qs);
- vl ans(q);
- vector<vl> lb(n + 1), rb(n + 1);
- for (auto [x, y] : rs) {
- dbg(x, y);
- assert(x >= 1 && x <= n);
- assert(y >= 1 && y <= n);
- lb[y].push_back(x), rb[x].push_back(y);
- }
- for (auto &x : lb)
- rngs::sort(x);
- for (auto &x : rb)
- rngs::sort(x);
- for (auto [x, y, id] : qs) {
- if (cnt.count({x, y}) && cnt[{x, y}] >= 2) {
- ans[id] = 1;
- continue;
- }
- if (rb[x].empty())
- continue;
- auto it = upper_bound(rb[x].begin(), rb[x].end(), y - 1) - rb[x].begin();
- if (it == 0)
- continue;
- ll v = rb[x][it - 1];
- if (lb[y].empty())
- continue;
- auto it2 = upper_bound(lb[y].begin(), lb[y].end(), x) - lb[y].begin();
- if (it2 != lb[y].size() && lb[y][it2] <= v)
- ans[id] = 1, dbg(lb[y][it2], v);
- }
- for (auto x : ans)
- cout << (x ? "Yes" : "No") << endl;
- }
- int main(int argc, char **argv)
- {
- std::ios::sync_with_stdio(false);
- std::cin.tie(nullptr);
- ll t = 1;
- // cin >> t;
- while (t--)
- solve();
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment