NC230850. A Bite of Teyvat
描述
输入描述
The first line contains an integer , indicating the number of plates Xiangling has bought.
Then follow lines, the -th of which contains two integers and , indicating that the -th plate placed by Guoba has radius and the center of this plate locates at on the table.
输出描述
Output lines, the -th of which contains a real number, indicating the total area covered by the plates on the table after Guoba places the first -th plates.
Your answer is acceptable if its absolute or relative error does not exceed . Formally speaking, suppose that your output is and the jury's answer is , your output is accepted if and only if .
示例1
输入:
4 0 1 2 1 3 1 1 1
输出:
3.141592653589793 6.283185307179586 8.196408262160623 8.881261518532902
说明:
In the sample case:C++ 解法, 执行用时: 330ms, 内存消耗: 10580K, 提交时间: 2021-11-22 11:47:06
#include <bits/stdc++.h> using namespace std; typedef long long s64; s64 sqr(int x) { return s64(x) * x; } const double PI = acos(-1); const int N = 1e5 + 5; int x[N], r[N]; double la[N], ra[N]; int q[N], pos[N]; set<int> S; double ans; double area(int i) { if (la[i] <= ra[i]) return 0; return sqr(r[i]) * (la[i] - ra[i] + (sin(2 * ra[i]) - sin(2 * la[i])) / 2) / 2; } void check(int pl, int pr) { int d = x[pr] - x[pl]; int r1 = r[pl], r2 = r[pr]; if (d >= r1 + r2) return; ans -= area(pl) + area(pr); if (r2 >= r1 + d) { ra[pl] = PI; } else if (r1 >= r2 + d) { ra[pr] = PI; } else { double lx = (d + double(sqr(r1) - sqr(r2)) / d) / 2; ra[pl] = max(ra[pl], acos(lx / r1)); la[pr] = min(la[pr], acos((-d + lx) / r2)); } ans += area(pl) + area(pr); } void add(int i) { auto it = S.insert(pos[i]).first; la[i] = PI; ra[i] = 0; ans += area(i); while (it != S.begin()) { auto it0 = it; --it0; int pl = q[*it0]; check(pl, i); if (la[i] <= ra[i]) return; if (la[pl] > ra[pl]) break; S.erase(it0); } while (1) { auto it1 = it; ++it1; if (it1 == S.end()) break; int pr = q[*it1]; check(i, pr); if (la[i] <= ra[i]) return; if (la[pr] > ra[pr]) break; S.erase(it1); } } int main() { #ifdef kcz freopen("1.in", "r", stdin); //freopen("1.out","w",stdout); #endif int n; cin >> n; for (int i = 1; i <= n; ++i) { scanf("%d%d", x + i, r + i); q[i] = i; } sort(q + 1, q + n + 1, [&](int a, int b) { return x[a] < x[b]; }); for (int i = 1; i <= n; ++i) pos[q[i]] = i; for (int i = 1; i <= n; ++i) { add(i); printf("%.9f\n", ans * 2); } }