Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define task "SAFEGUARD"
- #include <iostream>
- #include <cstdio>
- #include <vector>
- #include <algorithm>
- #include <cmath>
- using namespace std;
- using ll = long long;
- using ld = long double;
- template <class T>
- void read(T &x)
- {
- x = 0;
- register int c;
- while ((c = getchar()) && (c > '9' || c < '0'))
- ;
- for (; c >= '0' && c <= '9'; c = getchar())
- x = x * 10 + c - '0';
- }
- constexpr int N = 1e5 + 5;
- struct Point
- {
- ll x, y;
- int id;
- Point(ll x = 0, ll y = 0) : x(x), y(y) {}
- Point operator-(const Point &a) const
- {
- return Point(x - a.x, y - a.y);
- }
- bool operator<(const Point &a) const
- {
- return x < a.x || (x == a.x && y < a.y);
- }
- ll operator*(const Point &a) const
- {
- return x * a.y - y * a.x;
- }
- ll len()
- {
- return x * x + y * y;
- }
- ll operator&(const Point &a) const
- {
- return x * a.x + y * a.y;
- }
- bool operator==(const Point &a) const
- {
- return x == a.x && y == a.y;
- }
- } a[N], b[N];
- int n, m, l;
- bool ans[N];
- void Read()
- {
- //read(n);
- cin >> n;
- for (int i = 1; i <= n; ++i)
- //read(a[i].x), read(a[i].y);
- cin >> a[i].x >> a[i].y;
- //read(m);
- cin >> m;
- for (int i = 1; i <= m; ++i)
- //read(b[i].x), read(b[i].y),
- cin >> b[i].x >> b[i].y, b[i].id = i;
- l = m;
- }
- void ConvexHull()
- {
- sort(a + 1, a + n + 1);
- sort(a + 2, a + n + 1, [&](const Point &x, const Point &y)
- {
- Point u = x - a[1],
- v = y - a[1];
- return u * v > 0 || (u * v == 0 && u.len() < v.len());
- });
- vector<Point> s;
- s.reserve(n);
- a[n + 1] = a[1];
- for (int i = 1; i <= n + 1; ++i)
- {
- while (s.size() > 2 && (a[i] - s[s.size() - 2]) * (s.back() - s[s.size() - 2]) >= 0)
- s.pop_back();
- s.emplace_back(a[i]);
- }
- s.pop_back();
- n = s.size();
- for (int i = 1; i <= n; ++i)
- a[i] = s[i - 1];
- }
- void Sub_2()
- {
- ConvexHull();
- //for (int i = 1; i <= n; ++i)
- // cout << i << ": " << a[i].x << " " << a[i].y << '\n';
- sort(b + 1, b + m + 1, [&](const Point &x, const Point &y)
- { return x.x > y.x || (x.x == y.x && x.y > y.y); });
- while (m && (b[m].x < a[1].x || (b[m].x == a[1].x && b[m].y <= a[1].y)))
- --m;
- sort(b + 1, b + m + 1, [&](const Point &x, const Point &y)
- {
- Point u = x - a[1],
- v = y - a[1];
- return u * v > 0 || (u * v == 0 && u.len() < v.len());
- });
- a[0] = a[n];
- a[n + 1] = a[1];
- for (int i = 1, j = 2; i <= m; ++i)
- {
- while (j <= n && (a[j] - a[1]) * (b[i] - a[1]) >= 0)
- ++j;
- Point u = a[j - 1] - b[i],
- v = a[j] - b[i];
- if (u * v > 0 && (j > 3 || (a[1] - b[i]) * (a[2] - b[i]) > 0))
- ans[b[i].id] = 1;
- //cout << i << ":: " << j << " " << b[i].x << " " << b[i].y << " " << u * v << "\n";
- }
- for (int i = 1; i <= l; ++i)
- cout << (ans[i] ? "YES\n" : "NO\n");
- }
- int32_t main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- if (fopen(task ".INP", "r"))
- {
- freopen(task ".INP", "r", stdin);
- freopen(task ".OUT", "w", stdout);
- }
- Read();
- Sub_2();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement