1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
| #include <algorithm> #include <cassert> #include <cmath> #include <iostream> #include <ranges> #include <utility> #include <set> #include <vector> using i64 = long long; constexpr i64 M = 1e9 + 7;
struct pvec { int x, y; friend std::istream &operator>>(std::istream &is, pvec &a) { return is >> a.x >> a.y; } friend std::ostream &operator<<(std::ostream &os, const pvec &a) { return os << a.x << ' ' << a.y; } bool operator==(const pvec &a) const { return x == a.x && y == a.y; } pvec operator-(const pvec &a) const { return {x - a.x, y - a.y}; } bool operator<(const pvec &a) const { return x == a.x ? y < a.y : x < a.x; } };
int sign(i64 val) { return val < 0 ? -1 : (val > 0 ? 1 : 0); } i64 cross(const pvec &a, const pvec &b) { return 1ll * a.x * b.y - 1ll * a.y * b.x; } i64 cross(const pvec &a, const pvec &b, const pvec &c) { return cross(b - a, c - a); } i64 dot(const pvec &a, const pvec &b) { return 1ll * a.x * b.x + 1ll * a.y * b.y; } int scross(const pvec &a, const pvec &b, const pvec &c) { return sign(cross(a, b, c)); } i64 sqrlen(const pvec &a) { return dot(a, a); }
auto convex_hull(const std::vector<pvec> &x) { std::vector<pvec> v(x); std::vector<pvec> used, unused; std::sort(v.begin(), v.end()); int m = v.size(), tp = -1; for (int i = 0; i < m; i++) { while (tp > 0 && cross(used[tp-1], used[tp], v[i]) <= 0) tp--, used.pop_back(); used.push_back(v[i]), tp++; } int t = tp; for (int i = m - 1; i >= 0; i--) { while (tp > t && cross(used[tp-1], used[tp], v[i]) <= 0) { tp--; used.pop_back(); } used.push_back(v[i]), tp++; } used.pop_back(); std::set<pvec> s; for(auto d: used) s.insert(d); for(auto d: v) if (!s.contains(d)) unused.push_back(d); return std::pair{used, unused}; } bool comp(const pvec &a, const pvec &b) { bool upA = a.y > 0 || (a.y == 0 && a.x >= 0); bool upB = b.y > 0 || (b.y == 0 && b.x >= 0); if (upA != upB) return upA; auto val = cross(a, b); return val > 0; } i64 area(const std::vector<pvec> &p) { i64 res = 0; for (int i = 0, m = p.size(); i < m; i++) res += cross(p[i], p[(i + 1) % m]); return res; }
void run() { int n; std::cin >> n;
std::vector<pvec> p(n); for (auto &x : p) std::cin >> x;
auto [used, un] = convex_hull(p); int sz = used.size(); i64 ans = 0;
for (const auto &x : un) { std::vector<std::pair<pvec, int>> al; std::vector<pvec> cur(sz); std::vector<i64> val(sz, 0); i64 sum = 0;
for (const auto &y : un) { if (y == x) continue; al.push_back({y - x, -1}); } for (int i = 0; i < sz; i++) { cur[i] = used[i] - x; al.push_back({cur[i], i}); } std::sort(al.begin(), al.end(), [&](const auto &a, const auto &b) { return comp(a.first, b.first); });
for (int i = 0; i < al.size(); i++) { if (al[i].second == -1) continue; std::rotate(al.begin(), al.begin() + i, al.end()); break; }
for (int i = 0; i < sz; i++) { val[i] = cross(cur[i], cur[(i + 1) % sz]); sum += val[i]; }
for (int l = 0, r = 0, al_size = al.size(); l < al_size; l = r) { r = l + 1; while (r < al_size && al[r].second == -1) r++;
int pos = al[l].second; std::vector<i64> T(r - l, 0); assert((pos + 1) % sz == al[r % al_size].second);
[&al, &T, &l, &r] { std::vector<pvec> pts; int top = -1; i64 ssum = 0;
for (int fix = l; fix < r; fix++) { const auto &q = al[fix].first; while (top >= 1 && cross(q - pts[top - 1], pts[top] - pts[top - 1]) >= 0) { ssum -= cross(pts[top - 1], pts[top]); top--, pts.pop_back(); } pts.push_back(q), top++; if (top >= 1) ssum += cross(pts[top - 1], pts[top]);
T[fix - l] += ssum; } }(); [&al, &T, &l, &r, &al_size] { std::vector<pvec> pts; int top = -1; i64 ssum = 0;
for (int fix = r; fix > l; fix--) { const auto &q = al[fix % al_size].first; while (top >= 1 && cross(pts[top - 1], pts[top], q) >= 0) { ssum -= cross(pts[top], pts[top - 1]); top--, pts.pop_back(); } pts.push_back(q); top++; if (top >= 1) ssum += cross(pts[top], pts[top - 1]);
T[fix - l - 1] += ssum; } }();
for (int i = 0; i < r - l; i++) { i64 st = sum - val[pos] + T[i]; (ans += std::abs(st)) %= M; } } }
std::cout << ans << '\n'; }
int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr);
int T = 1; while (T--) run();
return 0; }
|