Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- // tiom4eg's precompiler options
- // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
- // IO settings
- #define fastIO ios_base::sync_with_stdio(false); cin.tie(0)
- // Quick types
- #define ll long long
- //#define ld double
- #define ull unsigned long long
- #define pii pair <int, int>
- #define pll pair <ll, ll>
- #define vi vector <int>
- #define mi vector <vector <int> >
- // Quick functions
- #define endl "\n"
- #define F first
- #define S second
- #define all(a) a.begin(), a.end()
- #define sz(a) a.size()
- #define pb push_back
- #define mp make_pair
- //#define min(a, b) ((a < b) ? (a) : (b))
- //#define max(a, b) ((a > b) ? (a) : (b))
- // Quick fors
- #define FOR(i, a, b) for (int i = a; i < b; ++i)
- #define RFOR(i, a, b) for (int i = a; i >= b; --i)
- // Pragmas
- #pragma GCC optimize("O3,unroll-loops") // let the chaos begin!
- //#pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt,tune=native")
- #pragma GCC comment(linker, "/stack:200000000")
- // PBDS
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #define ordered_set tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>
- #define ook order_of_key
- #define fbo find_by_order
- // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
- using namespace std;
- using namespace __gnu_pbds;
- mt19937 rng(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
- #define int long long
- #define pii pair <int, int>
- int rand(int n) { return rng() % n + 1; }
- int randrange(int l, int r) { return rng() % (r - l) + l; } // >= l && <= r
- // can you phil mahar
- struct pt { int x, y; };
- struct ang { int a, b; };
- bool operator<(const ang& p, const ang& q) { return ((!p.b && !q.b) ? (p.a < q.a) : (p.a * q.b < p.b * q.a)); }
- int sq(const pt& a, const pt& b, const pt& c) { return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y); }
- bool on(const pt& a, const pt& b, const pt& x) { return min(a.x, b.x) <= x.x <= max(a.x, b.x) && ((x.x - a.x) * (b.y - a.y) - (x.y - a.y) * (b.x - a.x) == 0); }
- int area(const vector <pt>& p) { // get double area of figure
- int n = sz(p);
- int s = 0;
- FOR(i, 0, n) s += p[i].x * p[i == n - 1 ? 0 : i + 1].y - p[i].y * p[i == n - 1 ? 0 : i + 1].x;
- return abs(s);
- }
- struct polygon {
- vector <pt> p;
- vector <ang> a;
- int ar, st = 0, n;
- pt start;
- void calc(vector <pt>& c) {
- n = sz(c);
- p.resize(n);
- FOR(i, 0, n) {
- p[i] = c[i];
- if (p[i].x < p[st].x || p[i].x == p[st].x && p[i].y < p[st].y) st = i;
- }
- ar = area(p);
- start = p[st];
- rotate(p.begin(), p.begin() + st, p.end());
- p.erase(p.begin());
- n--;
- a.resize(n);
- FOR(i, 0, n) {
- a[i].a = p[i].y - start.y, a[i].b = p[i].x - start.x;
- if (!a[i].a) a[i].b = a[i].b < 0 ? -1 : 1;
- }
- }
- bool in(const pt& q) {
- if (q.x < start.x) return false;
- if (q.x == start.x && q.y == start.y) return true;
- ang now = {q.y - start.y, q.x - start.x};
- if (!now.a) now.b = now.b < 0 ? -1 : 1;
- auto it = upper_bound(all(a), now);
- if (it == a.end() && now.a == a[n - 1].a && now.b == a[n - 1].b) --it;
- if (it != a.end() && it != a.begin()) {
- int pos = (int)(it - a.begin());
- if (on(p[pos], p[pos - 1], q)) return false;
- if (sq(p[pos], p[pos - 1], q) <= 0) return true;
- }
- return false;
- }
- };
- signed main() {
- fastIO;
- cout << fixed << setprecision(6);
- int n; cin >> n;
- vector <polygon> pol(n);
- FOR(i, 0, n) {
- int s; cin >> s;
- vector <pt> f(s);
- FOR(i, 0, s) cin >> f[i].x >> f[i].y;
- pol[i].calc(f);
- }
- sort(all(pol), [](const polygon& a, const polygon& b){ return a.ar > b.ar; });
- int m; cin >> m;
- int res = 0;
- FOR(i, 0, m) {
- pt q; cin >> q.x >> q.y;
- if (pol[0].in(q)) {
- int l = 0, r = n;
- while (l < r - 1) {
- int mid = (l + r) / 2;
- if (pol[mid].in(q)) l = mid;
- else r = mid;
- }
- if (l == n - 1) res += pol[l].ar;
- else res += pol[l].ar - pol[r].ar;
- }
- }
- cout << (long double)(res) / 2.0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement