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
- // can you phil mahar
- int sign(int x) {
- if (x > 0) return 1;
- if (x < 0) return -1;
- return 0;
- }
- struct pt {
- int x, y;
- pt() {}
- pt(int _x, int _y) : x(_x), y(_y) {}
- pt operator+(const pt &p) const { return pt(x + p.x, y + p.y); }
- pt operator-(const pt &p) const { return pt(x - p.x, y - p.y); }
- int operator*(const pt& oth) const { return x * oth.x + y * oth.y; }
- int operator^(const pt& oth) const { return x * oth.y - y * oth.x; }
- bool operator<(const pt& oth) const {
- if (sign(x - oth.x)) return x < oth.x;
- if (sign(y - oth.y)) return y < oth.y;
- return false;
- }
- bool operator==(const pt& oth) const { return !sign(x - oth.x) && !sign(y - oth.y); }
- };
- bool ccw(const pt& a, const pt& b, const pt& c) {
- return ((a.x - c.x) * (b.y - c.y) - (a.y - c.y) * (b.x - c.x)) > 0;
- }
- bool in_angle(const pt& a, const pt& b, const pt& c, const pt& x) {
- return (ccw(c, a, x) && !ccw(c, b, x)) || (!ccw(c, a, x) && ccw(c, b, x));
- }
- bool in_triangle(const pt& a, const pt& b, const pt& c, const pt& x) {
- return x == a || x == b || x == c || in_angle(a, b, c, x) && in_angle(c, a, b, x);
- }
- bool on_segment(const pt& a, const pt& b, const pt& x) {
- return (sign((x - a).x) != sign((x - b).x) && (x - a).x * (x - b).y == (x - a).y * (x - b).x);
- }
- int area(const vector <pt>& p) {
- int n = sz(p);
- int s = 0;
- FOR(i, 0, n) s += p[i] ^ p[i == n - 1 ? 0 : i + 1];
- return abs(s);
- }
- struct polygon {
- vector <pt> p;
- int n, ar;
- void init(vector <pt>& f) {
- n = sz(f), ar = area(f);
- int pos = 0;
- FOR(i, 1, n) if (f[i] < f[pos]) pos = i;
- p.resize(n);
- FOR(i, 0, n - pos) p[i] = f[pos + i];
- FOR(i, n - pos, n) p[i] = f[i - (n - pos)];
- }
- bool in(const pt& x) {
- if (p[0] == x) return true;
- if (!in_angle(p[1], p[n - 1], p[0], x)) return false;
- int l = 0, r = n - 2;
- while (l < r - 1) {
- int m = (l + r) / 2;
- if (in_angle(p[l + 1], p[m + 2], p[0], x)) l = m;
- else r = m;
- }
- //cout << l << ' ' << r << endl;
- //cout << p[l + 1].x << ' ' << p[l + 1].y << endl;
- //cout << p[l + 2].x << ' ' << p[l + 2].y << endl;
- return in_triangle(p[l + 1], p[l + 2], p[0], x);
- }
- };
- /*
- 1
- 4
- 2 2
- -2 2
- -2 -2
- 2 -2
- 1
- -2 2
- */
- 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].init(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.0L;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement