Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef _DEBUG
- #define _GLIBCXX_DEBUG
- #endif
- #define _CRT_SECURE_NO_WARNINGS
- #include <ext/pb_ds/assoc_container.hpp>
- #include <bits/stdc++.h>
- using namespace __gnu_pbds;
- using namespace std;
- typedef long long ll;
- typedef vector<ll> vll;
- typedef pair<int, int> pii;
- typedef vector<int> vi;
- typedef long double ld;
- typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
- #define mk make_pair
- #define inb push_back
- #define enb emplace_back
- #define X first
- #define Y second
- #define all(v) v.begin(), v.end()
- #define sqr(x) (x) * (x)
- #define TIME 1.0 * clock() / CLOCKS_PER_SEC
- #define y1 AYDARBOG
- //continue break pop_back return
- int solve();
- int main()
- {
- //ios_base::sync_with_stdio(0);
- //cin.tie(0);
- #define TASK "robots"
- #ifndef _DEBUG
- //freopen(TASK".in", "r", stdin), freopen(TASK".out", "w", stdout);
- #endif
- solve();
- #ifdef _DEBUG
- fprintf(stderr, "\nTIME: %.3f\n", TIME);
- #endif
- }
- struct Point
- {
- ll x, y;
- Point() {};
- Point(ll x, ll y) : x(x), y(y) {};
- Point operator-(Point a)
- {
- return Point(x - a.x, y - a.y);
- }
- ll operator*(Point a)
- {
- return x * a.y - y * a.x;
- }
- bool operator==(Point a)
- {
- return x == a.x && y == a.y;
- }
- };
- ll dst(Point a, Point b)
- {
- return sqr(a.x - b.x) + sqr(a.y - b.y);
- }
- Point makeV(Point a, Point b)
- {
- return b - a;
- }
- struct event
- {
- int x, l, r;
- event() {};
- event(int x, int l, int r) : x(x), l(l), r(r) {};
- bool operator< (event &a) const
- {
- if (x == a.x)
- return l < a.l;
- return x < a.x;
- }
- };
- ll mysqrt(ll x)
- {
- ll l = 0, r = 3e9;
- while (r - l > 1)
- {
- ll mid = l + r >> 1ll;
- if (mid * mid <= x)
- l = mid;
- else
- r = mid;
- }
- return l;
- }
- int solve()
- {
- int n;
- cin >> n;
- vector<Point> a(n);
- Point l, r;
- for (int i = 0; i < n; ++i)
- {
- cin >> a[i].x >> a[i].y;
- if (!i)
- {
- l = a[i], r = a[i];
- }
- else
- {
- if (a[i].x < l.x || a[i].x == l.x && a[i].y < l.y)
- l = a[i];
- if (a[i].x > r.x || a[i].x == r.x && a[i].y < r.y)
- r = a[i];
- }
- }
- vector<Point> up, dn;
- up.inb(l);
- dn.inb(l);
- Point veclr = makeV(l, r);
- for (int i = 0; i < n; ++i)
- {
- Point vec = makeV(l, a[i]);
- ll crpr = vec * veclr;
- if (crpr < 0)
- up.inb(a[i]);
- if (crpr > 0)
- dn.inb(a[i]);
- }
- up.inb(r);
- dn.inb(r);
- sort(up.begin() + 1, up.end(), [&](Point p, Point t)
- {
- Point v = makeV(up[0], p);
- Point v1 = makeV(up[0], t);
- return v * v1 < 0;
- });
- sort(dn.begin() + 1, dn.end(), [&](Point p, Point t)
- {
- Point v = makeV(dn[0], p);
- Point v1 = makeV(dn[0], t);
- return v * v1 > 0;
- });
- int q;
- cin >> q;
- vector<event> sc;
- while (q--)
- {
- ll x, y, R;
- cin >> x >> y >> R;
- for (int cx = max(l.x, x - R); cx <= min(r.x, x + R); ++cx)
- {
- ll val = 0;
- ll xx = cx - x;
- {
- ll l = 0, r = 1e9;
- while (r - l > 1)
- {
- ll mid = l + r >> 1;
- if (sqr(xx) + sqr(mid) <= sqr(R))
- l = mid;
- else
- r = mid;
- }
- val = l;
- }
- sc.inb(event(cx, y - val, y + val));
- }
- }
- sort(all(sc));
- int iu = 1;
- int id = 1;
- int i = 0;
- ll ans = 0;
- while (i < (int)sc.size())
- {
- int cx = sc[i].x;
- while (cx > up[iu].x)
- ++iu;
- while (cx > dn[id].x)
- ++id;
- vector<pii> s;
- Point vup = makeV(up[iu - 1], up[iu]);
- Point vdn = makeV(dn[id - 1], dn[id]);
- ll U;
- //up check
- {
- ll L = -2e9, R = 2e9;
- while (R - L > 1)
- {
- ll mid = (L + R) / 2ll;
- Point vcur = makeV(up[iu - 1], Point(cx, mid));
- if (vcur * vup < 0)
- R = mid;
- else
- L = mid;
- }
- U = L;
- }
- ll D;
- //down check
- {
- ll L = -2e9, R = 2e9;
- while (R - L > 1)
- {
- ll mid = (L + R) / 2ll;
- Point vcur = makeV(dn[id - 1], Point(cx, mid));
- if (vcur * vdn <= 0)
- R = mid;
- else
- L = mid;
- }
- D = R;
- }
- while (i < (int)sc.size() && sc[i].x == cx)
- {
- ll cl = max((ll)sc[i].l, D);
- ll cr = min((ll)sc[i].r, U);
- if (cl <= cr)
- {
- s.inb(mk(cl, -1));
- s.inb(mk(cr, 1));
- }
- ++i;
- }
- sort(all(s));
- ll lst = -1;
- int bal = 0;
- for (auto &e : s)
- {
- bal += e.Y;
- if (bal == -1 && e.Y == -1)
- lst = e.X;
- if (bal == 0 && e.Y == 1)
- {
- ans += e.X - lst + 1;
- }
- }
- }
- printf("%lld\n", ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement