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;
- 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;
- void Read()
- {
- read(n);
- for (int i = 1; i <= n; ++i)
- read(a[i].x), read(a[i].y);
- read(m);
- for (int i = 1; i <= m; ++i)
- read(b[i].x), read(b[i].y);
- }
- 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];
- }
- ll Size(Point a[N], int n)
- {
- ll ans(0);
- for (int i = 1; i < n; ++i)
- ans += a[i] * a[i + 1];
- ans += a[n] * a[1];
- return abs(ans);
- }
- void Sub_1()
- {
- ConvexHull();
- ll S = Size(a, n);
- if (Size(a, n) == 0)
- {
- cout << 0;
- return;
- }
- int ans(0);
- for (int i = 1; i <= m; ++i)
- {
- ll tmp(0);
- for (int j = 1; j < n; ++j)
- tmp += abs((a[j] - b[i]) * (a[j + 1] - b[i]));
- tmp += abs((a[n] - b[i]) * (a[1] - b[i]));
- if (S == tmp)
- ++ans;
- }
- cout << ans;
- }
- void Sub_2()
- {
- ConvexHull();
- //for (int i = 1; i <= n; ++i)
- // cout << a[i].x << " " << a[i].y << "\n";
- int ans(0);
- if (Size(a, n) == 0)
- {
- cout << 0;
- return;
- }
- 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)))
- ans += 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;
- //cout << (a[2] - a[1]) * (b[i] - a[1]) << "\n";
- Point u = a[j - 1] - b[i],
- v = a[j] - b[i];
- if (u * v == 0 && (b[i] == a[j] || b[i] == a[j - 1] || (u & v) < 0))
- ++ans;
- //cout << i << ": " << j << " --- " << b[i].x << " " << b[i].y << " --- " << ans << '\n';
- }
- cout << ans;
- }
- 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();
- //if (1ll * m * n <= 2e7)
- // Sub_1();
- //else
- Sub_2();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement