{"id":510,"date":"2025-11-20T22:31:21","date_gmt":"2025-11-20T14:31:21","guid":{"rendered":"https:\/\/www.xgnd.net\/?p=510"},"modified":"2025-12-04T18:02:52","modified_gmt":"2025-12-04T10:02:52","slug":"%e3%80%8c%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0%e3%80%8d%e8%ae%a1%e7%ae%97%e5%87%a0%e4%bd%95%ef%bc%88%e4%b8%80%ef%bc%89-%e6%89%ab%e6%8f%8f%e7%ba%bf%e5%a4%84%e7%90%86%e5%8c%85%e5%90%ab","status":"publish","type":"post","link":"https:\/\/www.xgnd.net\/index.php\/2025\/11\/20\/%e3%80%8c%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0%e3%80%8d%e8%ae%a1%e7%ae%97%e5%87%a0%e4%bd%95%ef%bc%88%e4%b8%80%ef%bc%89-%e6%89%ab%e6%8f%8f%e7%ba%bf%e5%a4%84%e7%90%86%e5%8c%85%e5%90%ab\/","title":{"rendered":"\u300c\u5b66\u4e60\u7b14\u8bb0\u300d\u8ba1\u7b97\u51e0\u4f55\uff08\u4e00\uff09\u2014\u2014\u626b\u63cf\u7ebf\u5904\u7406\u5305\u542b\u5173\u7cfb"},"content":{"rendered":"<h2>\u5706\u7684\u626b\u63cf\u7ebf\u7b97\u6cd5<\/h2>\n<h3>\u5f15\u5165<\/h3>\n<p>\u5e73\u9762\u4e0a\u6709 $n$ \u4e2a\u5706\uff0c\u5706\u4e4b\u95f4\u6ca1\u6709\u516c\u5171\u70b9\uff0c\u5373\u5706\u4e4b\u95f4\u8981\u4e48\u5305\u542b\uff0c\u8981\u4e48\u76f8\u79bb\u3002\u6b64\u65f6\u5706\u8981\u4e48\u90fd\u662f\u4e00\u4e2a\u5305\u542b\u4e00\u4e2a\uff0c\u8981\u4e48\u90fd\u662f\u540c\u7ea7\u5e76\u5217\u7684\uff0c\u4e0d\u96be\u53d1\u73b0\u8fd9\u5f88\u50cf\u6811\u7684\u7ed3\u6784\uff0c\u90a3\u6211\u4eec\u4e0d\u59a8\u5c06\u5706\u7684\u5305\u542b\u5173\u7cfb\u770b\u505a\u6811\u7684\u8fb9\u7136\u540e\u5efa\u6811\uff0c\u8fd9\u6837\u5c31\u4f1a\u5f62\u6210\u4e00\u4e2a\u68ee\u6797\u3002\u6211\u4eec\u53ef\u4ee5\u7ed9\u68ee\u6797\u4e00\u4e2a\u8d85\u7ea7\u6e90\u70b9\uff0c\u5c06\u68ee\u6797\u4e2d\u6240\u6709\u6811\u7684\u6839\u8fde\u8d77\u6765\uff0c\u6b64\u65f6\u68ee\u6797\u5c31\u53d8\u6210\u4e86\u4e00\u68f5\u6811\uff0c\u76f8\u5f53\u4e8e\u6b64\u65f6\u539f\u70b9\u5904\u6709\u4e00\u4e2a\u534a\u5f84\u65e0\u9650\u5927\u7684\u5706\uff0c\u6240\u6709\u5706\u90fd\u88ab\u5305\u542b\u5176\u4e2d\u3002\u8fd9\u6837\u5c31\u80fd\u5c06\u5e73\u9762\u4e0a\u5706\u4e4b\u95f4\u7684\u95ee\u9898\u8f6c\u5316\u4e3a\u6811\u4e0a\u70b9\u4e4b\u95f4\u7684\u95ee\u9898\u3002<\/p>\n<p>\u90a3\u4e48\u6211\u4eec\u600e\u4e48\u627e\u51fa\u5706\u4e4b\u95f4\u7684\u5305\u542b\u5173\u7cfb\u5462\uff1f\u6b64\u4e3a\u95ee\u9898\u7684\u6838\u5fc3\u3002<\/p>\n<p>\u6734\u7d20\u7684\uff0c\u6211\u4eec\u53ef\u4ee5\u679a\u4e3e\u4e24\u4e2a\u5706\u6765\u5224\u65ad\uff0c\u8fd9\u6837\u662f $\\mathcal{O}(n^2)$ \u7684\uff0c\u6709\u6ca1\u6709\u66f4\u4f18\u7684\u505a\u6cd5\u5462\uff1f<\/p>\n<p>\u6211\u4eec\u4e0d\u59a8\u5148\u6765\u601d\u8003\u4e00\u4e0b\u5982\u679c\u662f\u77e9\u5f62\u8be5\u600e\u4e48\u5904\u7406\u3002<\/p>\n<p>\u5982\u679c\u6309\u7167\u626b\u63cf\u7ebf\u6b63\u5e38\u7684\u6d41\u7a0b\uff0c\u9047\u5230\u4e00\u4e2a\u77e9\u5f62\u7684\u5de6\u8fb9\u754c\uff0c\u6211\u4eec\u4f1a\u628a\u77e9\u5f62\u4e0a\u4e0b\u8fb9\u754c\u56f4\u6210\u7684\u533a\u95f4\u4e22\u5230\u7ebf\u6bb5\u6811\u91cc\u7ef4\u62a4\uff0c\u4f46\u8fd9\u91cc\u6211\u4eec\u5e0c\u671b\u8981\u627e\u51fa\u4ed6\u4eec\u4e4b\u95f4\u7684\u5305\u542b\u5173\u7cfb\uff0c\u663e\u7136\u4e0d\u80fd\u8fd9\u4e48\u505a\uff0c\u56e0\u4e3a\u4e0d\u80fd\u901a\u8fc7\u7ebf\u6bb5\u6811\u627e\u5230\u4e00\u4e2a\u533a\u95f4\u7684\u7236\u533a\u95f4\u3002\u5982\u679c\u4f60\u4ed4\u7ec6\u89c2\u5bdf\u4f1a\u53d1\u73b0\uff0c\u8fd9\u4e9b\u533a\u95f4\u5176\u5b9e\u5c31\u50cf\u4e00\u4e2a\u62ec\u53f7\u5e8f\u5217\uff0c\u60f3\u8c61\u4e00\u4e0b\u77e9\u5f62\u4e0a\u8fb9\u754c\u662f\u5de6\u62ec\u53f7\uff0c\u4e0b\u8fb9\u754c\u662f\u53f3\u62ec\u53f7\uff0c\u77e9\u5f62\u4e4b\u95f4\u7684\u5305\u542b\u5173\u7cfb\u5c31\u50cf\u4e00\u4e2a\u62ec\u53f7\u5305\u542b\u53e6\u4e00\u4e2a\u62ec\u53f7\uff0c\u6b64\u65f6\u6211\u4eec\u5c31\u76f8\u5f53\u4e8e\u8981\u7ef4\u62a4\u4e00\u4e2a\u62ec\u53f7\u5e8f\u5217\u5e76\u80fd\u591f\u5feb\u901f\u627e\u5230\u4e00\u4e2a\u62ec\u53f7\u7684\u7236\u62ec\u53f7\uff08\u76f4\u63a5\u5305\u542b\u6b64\u62ec\u53f7\u7684\u62ec\u53f7\uff09\u3002\u6b64\u65f6\u6211\u4eec\u628a\u5de6\u53f3\u62ec\u53f7\u90fd\u4e22\u5230 set \u91cc\u6839\u636e\u5750\u6807\u7ef4\u62a4\u76f8\u5bf9\u4f4d\u7f6e\uff0c\u4e0d\u96be\u53d1\u73b0\uff0c\u63d2\u5165\u4e00\u5bf9\u62ec\u53f7\u65f6\uff0c\u6211\u4eec\u60f3\u8981\u627e\u7684\u7236\u62ec\u53f7\u4e00\u5b9a\u53ef\u4ee5\u901a\u8fc7\u76f8\u90bb\u62ec\u53f7\uff08\u524d\u9a71\u6216\u540e\u7ee7\u62ec\u53f7\uff09\u627e\u5230\uff0c\u8fd9\u6837\u5c31\u80fd\u5728 $\\mathcal{O}(n\\log n)$ \u7684\u65f6\u95f4\u5185\u5bf9\u77e9\u5f62\u5efa\u6811\u3002<\/p>\n<p>\u4e86\u89e3\u4e86\u77e9\u5f62\u600e\u4e48\u5904\u7406\uff0c\u90a3\u4e48\u5706\u7684\u505a\u6cd5\u5c31\u663e\u800c\u6613\u89c1\u4e86\u3002<\/p>\n<h3>\u7b97\u6cd5\u8fc7\u7a0b<\/h3>\n<p>\u5706\u4e0d\u540c\u4e8e\u77e9\u5f62\u90a3\u6837\u6709\u89c4\u5219\u7684\u4e0a\u4e0b\u754c\uff0c\u4f46\u6211\u4eec\u53ef\u4ee5\u7c7b\u6bd4\u4e0a\u8ff0\u7684\u601d\u60f3\uff0c\u5b9e\u73b0\u5706\u7684\u626b\u63cf\u7ebf\u3002<\/p>\n<p>\u9996\u5148\u548c\u4f20\u7edf\u626b\u63cf\u7ebf\u7684\u65b9\u6cd5\u4e00\u6837\u5148\u628a\u6bcf\u4e2a\u5706\u5de6\u53f3\u4fa7 $x$ \u5750\u6807\u79bb\u6563\u51fa\u6765\u6392\u4e2a\u5e8f\u6807\u8bb0\u597d\u8fdb\u51fa\uff0c\u7136\u540e\u5f00\u59cb\u626b\u63cf\u3002\u5728\u6bcf\u4e2a $x$ \u5904\uff0c\u626b\u63cf\u7ebf\u4ece\u4e0a\u5230\u4e0b\u4f1a\u548c\u4e00\u4e9b\u5706\u76f8\u4ea4\uff0c\u4ea4\u70b9\u5c06\u626b\u63cf\u7ebf\u5212\u5206\u4e3a\u82e5\u5e72\u533a\u95f4\uff08\u5982\u4e0b\u56fe\uff09\uff0c\u56e0\u4e3a\u5706\u4e4b\u95f4\u6ca1\u6709\u516c\u5171\u70b9\uff0c\u90a3\u4e48\u4ece\u4e0a\u5230\u4e0b\u626b\u63cf\u7ebf\u7a7f\u8fc7\u5706\u7684\u987a\u5e8f\u662f\u4e0d\u4f1a\u53d8\u7684\uff0c\u5bf9\u5e94\u7684\u8fd9\u4e9b\u533a\u95f4\u7684\u76f8\u5bf9\u987a\u5e8f\u4e5f\u4e0d\u4f1a\u53d8\uff0c\u4e8e\u662f\u6211\u4eec\u53ef\u4ee5\u7528\u4e00\u4e2a set \uff08\u6216\u5176\u4ed6\u5e73\u8861\u6811\uff0c\u8fd9\u91cc\u4f7f\u7528 set\uff09\u6765\u52a8\u6001\u5730\u7ef4\u62a4\u8fd9\u4e9b\u533a\u95f4\u3002<\/p>\n<p><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-493\" data-original=\"https:\/\/www.xgnd.net\/wp-content\/uploads\/2025\/11\/jsjh-1.1-300x300.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" width=\"300\" height=\"300\"  sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>\u5177\u4f53\u7684\uff0c\u6211\u4eec\u5c06\u5706\u62c6\u6210\u4e0a\u4e0b\u534a\u5706\uff08\u76f8\u5f53\u4e8e\u5de6\u53f3\u62ec\u53f7\uff09\uff0cset \u4e2d\u7684\u533a\u95f4\u9700\u8981\u7ef4\u62a4\u7684\u4fe1\u606f\u6709\u4e0a\u7aef\u70b9\u6240\u4ea4\u7684\u534a\u5706\u4e0e\u4e0b\u7aef\u70b9\u6240\u4ea4\u7684\u534a\u5706\uff0c\u4ee5\u53ca\u533a\u95f4\u6240\u5c5e\u7684\u7236\u5706\u3002\u6bcf\u6b21\u626b\u63cf\u5230\u4e00\u4e2a\u5706\u7684\u5de6\u7aef\u70b9\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4e8c\u5206\uff08lower_bound\uff09\u5728 set \u4e2d\u627e\u5230\u70b9\u6240\u5c5e\u7684\u533a\u95f4\uff0c\u901a\u8fc7\u8be5\u533a\u95f4\u627e\u5230\u7236\u5706\u5e76\u5efa\u8fb9\uff0c\u7136\u540e\u5c06\u6b64\u533a\u95f4\u5206\u88c2\u4e3a\u4e24\u4e2a\u533a\u95f4\u5e76\u66f4\u65b0\u4fe1\u606f\uff08\u5982\u679c\u4f60\u5b66\u8fc7\u73c2\u6735\u8389\u6811\u7684\u8bdd\uff0c\u4f1a\u53d1\u73b0\u8fd9\u548c\u73c2\u6735\u8389\u6811\u7684 split \u64cd\u4f5c\u5f88\u50cf\uff09\u3002\u8fd9\u6837\u6211\u4eec\u5c31\u80fd\u5728 $\\mathcal{O}(n\\log n)$ \u7684\u65f6\u95f4\u5185\u5bf9\u5706\u5efa\u6811\u3002<\/p>\n<h3>\u5b9e\u73b0<\/h3>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u662f\u57fa\u4e8e\u4e0a\u8ff0\u601d\u60f3\u5b9e\u73b0\u7684\uff0c\u7a0d\u5fae\u8fdb\u884c\u4e86\u4e00\u4e9b\u5c01\u88c5\u4fbf\u4e8e\u7406\u89e3\uff0c\u5982\u679c\u60f3\u8981\u4ee3\u7801\u7b80\u77ed\u4e00\u70b9\u5176\u5b9e\u5b9a\u4e49\u4e00\u4e2a\u7ed3\u6784\u4f53\u5c31\u591f\u4e86\uff0c\u4e0d\u9700\u8981\u5c06\u626b\u63cf\u7ebf\u5206\u6210\u4e00\u4e2a\u4e00\u4e2a\u533a\u95f4\uff0c\u76f4\u63a5\u628a\u5706\u62c6\u6210\u4e0a\u4e0b\u534a\u5706\u4e22\u8fdb set \u5c31\u884c\u4e86\uff0c\u5177\u4f53\u53ef\u4ee5\u53c2\u8003\u51f8\u591a\u8fb9\u5f62\u626b\u63cf\u7ebf\u7684\u4ee3\u7801 <del>\uff08\u5706\u7684\u61d2\u5f97\u518d\u5199\u4e00\u904d\u4e86\uff09<\/del>\u3002<\/p>\n<pre><code class=\"language-cpp\">#include &amp;lt;bits\/stdc++.h&amp;gt;\nusing namespace std;\ntypedef long long ll;\nconst int maxn = 100050, mod = 998244353, INF = 1e9;\nconst double eps = 1e-9;\nint sweep_line_x = -1e9;\nvector&amp;lt;int&amp;gt; g[maxn];\n\nstruct Circle {\n    int x, y, r;\n\n    double get_y(bool up_side) const {\n        int b = -2 * y;\n        ll c = (ll)y * y + (sweep_line_x - x) * ll(sweep_line_x - x) - (ll)r * r;\n        ll delta = (ll)b * b - 4 * c;\n        return (-b + (up_side ? sqrt(delta) : -sqrt(delta))) \/ 2;\n    }\n\n    bool operator&amp;lt;(const Circle&amp;amp; rhs) const {\n        return r &amp;lt; rhs.r;\n    }\n};\n\nstruct Curve {\n    bool up_side;\n    Circle c;\n\n    bool operator&amp;lt;(const Curve&amp;amp; rhs) const {\n        return c.get_y(up_side) + eps &amp;lt; rhs.c.get_y(rhs.up_side);\n    }\n};\n\nstruct Interval {\n    int id;\n    Curve up, down;\n\n    bool operator&amp;lt;(const Interval&amp;amp; rhs) const {\n        return down &amp;lt; rhs.down || up &amp;lt; rhs.up;\n    }\n\n    bool operator==(const Interval&amp;amp; rhs) const {\n        return !(*this &amp;lt; rhs) &amp;amp;&amp;amp; !(rhs &amp;lt; *this);\n    }\n};\n\nint main() {\n    ios::sync_with_stdio(0);\n    int n;\n    cin &amp;gt;&amp;gt; n;\n\n    vector&amp;lt;Circle&amp;gt; c(n + 1);\n    vector&amp;lt;pair&amp;lt;int, int&amp;gt;&amp;gt; events;\n    for (int i = 1;i &amp;lt;= n;i++) {\n        cin &amp;gt;&amp;gt; c[i].x &amp;gt;&amp;gt; c[i].y &amp;gt;&amp;gt; c[i].r;\n        events.emplace_back(c[i].x - c[i].r, i);\n        events.emplace_back(c[i].x + c[i].r, i);\n    }\n\n    c[0] = { 0,0,INF };\n    sort(events.begin(), events.end());\n\n    set&amp;lt;Interval&amp;gt; s;\n    s.insert({ 0, {true, c[0]}, {false, c[0]} });\n\n    for (auto &amp;amp;[x, id] : events) {\n        sweep_line_x = x;\n        Interval cur = { id, {true, c[id]}, {false, c[id]} };\n        if (x == c[id].x - c[id].r) { \/\/\u5706\u7684\u5de6\u7aef\u70b9\n            auto it = --s.lower_bound(cur);\n            auto par = *it;\n            s.erase(it);\n            g[par.id].push_back(id);\n            Interval up = par, down = par;\n            up.down = { true, c[id] };\n            down.up = { false, c[id] };\n            s.insert(up);\n            s.insert(down);\n            s.insert(cur);\n        }\n        else {  \/\/\u5706\u7684\u53f3\u7aef\u70b9\n            auto it = s.lower_bound(cur);\n            auto joined = *prev(it);\n            joined.up = next(it)-&amp;gt;up;\n            s.erase(prev(it));\n            s.erase(next(it));\n            s.erase(it);\n            s.insert(joined);\n        }\n    }\n\n    return 0;\n}<\/code><\/pre>\n<h3>\u4f8b\u9898<\/h3>\n<h4><a href=\"https:\/\/codeforces.com\/gym\/104279\/problem\/C\">\u5f80\u65e5\u91cd\u73b0<\/a><\/h4>\n<p>\u9898\u610f\uff1a\u6bcf\u6b21\u8be2\u95ee\u4ece $(x,y)$ \u5230 $(p,q)$ \u6700\u5c11\u8981\u7a7f\u8fc7\u591a\u5c11\u4e2a\u5706\u7684\u8fb9\u754c\uff0c$n$ \u4e2a\u5706\u4e4b\u95f4\u6ca1\u6709\u4efb\u4f55\u516c\u5171\u70b9\uff0c$n\\leq 10^5$\uff0c\u503c\u57df $10^7$\uff0c\u8be2\u95ee $10^5$ \u6b21\u3002<\/p>\n<p>\u56e0\u4e3a\u5706\u4e4b\u95f4\u4e0d\u76f8\u4ea4\uff0c\u90a3\u4e48\u5706\u4e4b\u95f4\u7684\u5305\u542b\u5173\u7cfb\u53ef\u4ee5\u770b\u505a\u6811\u7684\u8fb9\uff0c\u7a7f\u8fc7\u4e00\u4e2a\u5706\u7684\u8fb9\u754c\u5c31\u76f8\u5f53\u4e8e\u8d70\u8fc7\u6811\u4e0a\u7684\u4e00\u6761\u8fb9\uff0c\u6811\u4e0a\u4e24\u70b9\u95f4\u8ddd\u79bb\u5373\u4e3a\u7b54\u6848\u3002\u53ef\u4ee5\u4f7f\u7528\u5706\u7684\u626b\u63cf\u7ebf\u7b97\u6cd5\u5efa\u6811\uff0c\u67e5\u8be2\u7684\u65f6\u5019\u901a\u8fc7 LCA \u548c\u6811\u7684\u6df1\u5ea6\u5c31\u53ef\u6c42\u5f97\u4e24\u70b9\u6240\u5c5e\u5706\u5728\u6811\u4e0a\u7684\u6700\u77ed\u8ddd\u79bb\u3002\u56e0\u4e3a\u9898\u76ee\u95ee\u7684\u662f\u4e24\u70b9\u7684\u5173\u7cfb\uff0c\u6240\u4ee5\u8981\u5148\u6c42\u51fa\u6bcf\u4e00\u4e2a\u70b9\u5c5e\u4e8e\u54ea\u4e00\u4e2a\u5706\uff08\u8be5\u5706\u662f\u5305\u542b\u6b64\u70b9\u7684\u5706\u4e2d\u534a\u5f84\u6700\u5c0f\u7684\uff09\uff0c\u5c06\u70b9\u770b\u505a\u534a\u5f84\u4e3a 0 \u7684\u5706\u4e00\u5e76\u626b\u63cf\u5373\u53ef\uff0c\u9700\u8981\u5148\u5c06\u8be2\u95ee\u70b9\u79bb\u7ebf\u3002<\/p>\n<pre><code class=\"language-cpp\">#include &amp;lt;bits\/stdc++.h&amp;gt;\nusing namespace std;\ntypedef long long ll;\n#define int ll\nconst int maxn = 100050, mod = 998244353, INF = 1e9;\nconst double eps = 1e-9;\nint sweep_line_x = -1e9;\nvector&amp;lt;int&amp;gt; g[maxn];\nint dep[maxn], fa[maxn][22];\n\nstruct Circle {\n    int x, y, r;\n\n    double get_y(bool up_side) const {\n        int b = -2 * y;\n        ll c = (ll)y * y + (sweep_line_x - x) * ll(sweep_line_x - x) - (ll)r * r;\n        ll delta = b * (ll)b - 4 * c;\n        return (-b + (up_side ? sqrt(delta) : -sqrt(delta))) \/ 2;\n    }\n\n    bool operator&amp;lt;(const Circle&amp;amp; rhs) const {\n        return r &amp;lt; rhs.r;\n    }\n};\n\nstruct Curve {\n    bool up_side;\n    Circle c;\n\n    bool operator&amp;lt;(const Curve&amp;amp; rhs) const {\n        return c.get_y(up_side) + eps &amp;lt; rhs.c.get_y(rhs.up_side);\n    }\n};\n\nstruct Interval {\n    int id;\n    Curve up, down;\n\n    bool operator&amp;lt;(const Interval&amp;amp; rhs) const {\n        return down &amp;lt; rhs.down || up &amp;lt; rhs.up;\n    }\n\n    bool operator==(const Interval&amp;amp; rhs) const {\n        return !(*this &amp;lt; rhs) &amp;amp;&amp;amp; !(rhs &amp;lt; *this);\n    }\n};\n\nvoid dfs(int x, int fath) {\n    fa[x][0] = fath;\n    dep[x] = dep[fath] + 1;\n    for (int i = 1;i &amp;lt;= 20;i++) {\n        fa[x][i] = fa[fa[x][i - 1]][i - 1];\n    }\n    for (int to : g[x]) {\n        if (to == fath)continue;\n        dfs(to, x);\n    }\n}\n\nint lca(int x, int y) {\n    if (dep[x] &amp;lt; dep[y]) swap(x, y);\n\n    for (int i = 20;i &amp;gt;= 0;i--) {\n        if (dep[fa[x][i]] &amp;gt;= dep[y]) {\n            x = fa[x][i];\n        }\n        if (x == y) return x;\n    }\n    for (int i = 20;i &amp;gt;= 0;i--) {\n        if (fa[x][i] != fa[y][i]) {\n            x = fa[x][i];\n            y = fa[y][i];\n        }\n    }\n    return fa[x][0];\n}\n\nstruct Query {\n    pair&amp;lt;int, int&amp;gt; a, b;\n};\n\nvoid solve() {\n    int n, m;\n    cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; m;\n\n    vector&amp;lt;Circle&amp;gt; c(n + 1);\n    vector&amp;lt;pair&amp;lt;int, int&amp;gt;&amp;gt; events, p;\n    vector&amp;lt;Query&amp;gt; q(m + 1);\n    for (int i = 1;i &amp;lt;= n;i++) {\n        cin &amp;gt;&amp;gt; c[i].x &amp;gt;&amp;gt; c[i].y &amp;gt;&amp;gt; c[i].r ;\n        events.emplace_back(c[i].x - c[i].r, i);\n        events.emplace_back(c[i].x + c[i].r, i);\n    }\n\n    for (int i = 1;i &amp;lt;= m;i++) {\n        pair&amp;lt;int, int&amp;gt; a, b;\n        cin &amp;gt;&amp;gt; a.first &amp;gt;&amp;gt; a.second &amp;gt;&amp;gt; b.first &amp;gt;&amp;gt; b.second;\n        q[i] = { a,b };\n        p.push_back(a);\n        p.push_back(b);\n    }\n\n    sort(p.begin(), p.end());\n    p.erase(unique(p.begin(), p.end()), p.end());\n\n    vector&amp;lt;int&amp;gt; bel(p.size() + 1, 0);\n\n    for (int i = 0;i &amp;lt; p.size();i++) {\n        events.emplace_back(p[i].first, i + n + 1);\n    }\n\n    c[0] = { 0,0,INF };\n    sort(events.begin(), events.end());\n\n    set&amp;lt;Interval&amp;gt; s;\n    s.insert({ 0, {true, c[0]}, {false, c[0]} });\n\n    for (auto &amp;amp;[x, id] : events) {\n        sweep_line_x = x;\n        if (id &amp;gt; n) {   \/\/\u8981\u8be2\u95ee\u7684\u70b9\n            id -= n + 1;\n            Circle now = { p[id].first,p[id].second,0 };\n            Interval cur = { id, {true, now}, {false, now} };\n            auto it = --s.lower_bound(cur);\n            auto par = *it;\n            bel[id] = par.id;\n            continue;\n        }\n        Interval cur = { id, {true, c[id]}, {false, c[id]} };\n        if (x == c[id].x - c[id].r) { \/\/\u5706\u7684\u5de6\u7aef\u70b9\n            auto it = --s.lower_bound(cur);\n            auto par = *it;\n            s.erase(it);\n            g[par.id].push_back(id);\n            Interval up = par, down = par;\n            up.down = { true, c[id] };\n            down.up = { false, c[id] };\n            s.insert(up);\n            s.insert(down);\n            s.insert(cur);\n        }\n        else {  \/\/\u5706\u7684\u53f3\u7aef\u70b9\n            auto it = s.lower_bound(cur);\n            auto joined = *prev(it);\n            joined.up = next(it)-&amp;gt;up;\n            s.erase(prev(it));\n            s.erase(next(it));\n            s.erase(it);\n            s.insert(joined);\n        }\n    }\n\n    dfs(0, 0);\n\n    for (int i = 1;i &amp;lt;= m;i++) {\n        pair&amp;lt;int,int&amp;gt; a=q[i].a,b=q[i].b;\n        int x=lower_bound(p.begin(),p.end(),a)-p.begin();\n        int y=lower_bound(p.begin(),p.end(),b)-p.begin();\n        x=bel[x],y=bel[y];\n        cout&amp;lt;&amp;lt;dep[x]+dep[y]-2*dep[lca(x,y)]&amp;lt;&amp;lt;&amp;#039;\\n&amp;#039;;\n    }\n}\n\nsigned main() {\n    ios::sync_with_stdio(0);\n    int t = 1;\n    \/\/ cin&amp;gt;&amp;gt;t;\n    while (t--) {\n        solve();\n    }\n\n    return 0;\n}<\/code><\/pre>\n<h2>\u51f8\u591a\u8fb9\u5f62\u7684\u626b\u63cf\u7ebf<\/h2>\n<p>\u56de\u987e\u4e00\u4e0b\uff0c\u7531\u4e8e\u5706\u6ca1\u6709\u89c4\u5219\u7684\u4e0a\u4e0b\u754c\uff0c\u4e0d\u80fd\u50cf\u77e9\u5f62\u90a3\u6837\u7ef4\u62a4\uff0c\u4f46\u56e0\u4e3a\u6211\u4eec\u53ea\u662f\u5e0c\u671b\u786e\u5b9a\u5706\u4e4b\u95f4\u7684\u5305\u542b\u5173\u7cfb\uff0c\u6240\u4ee5\u6211\u4eec\u4f1a\u60f3\u5c06\u5706\u62c6\u6210\u4e0a\u4e0b\u534a\u5706\uff0c\u901a\u8fc7\u7b97\u534a\u5706\u4e0e\u626b\u63cf\u7ebf\u7684\u4ea4\u70b9\u4f4d\u7f6e\u6765\u786e\u5b9a\u76f8\u5bf9\u4f4d\u7f6e\u3002<\/p>\n<p>\u6211\u4eec\u53d1\u73b0\uff0c\u8fd9\u4e00\u8fc7\u7a0b\u9664\u4e86\u7b97\u4ea4\u70b9\u5916\u5176\u5b9e\u57fa\u672c\u6ca1\u7528\u5230\u5706\u672c\u8eab\u7684\u6027\u8d28\uff0c\u90a3\u4e48\u5982\u679c\u4e0d\u662f\u5706\u80fd\u4e0d\u80fd\u8fd9\u4e48\u505a\u5462\uff1f\u80fd\u4e0d\u80fd\u63a8\u5e7f\u4e00\u4e0b\u5462\uff1f<\/p>\n<p>\u4e0d\u96be\u53d1\u73b0\uff0c\u4e92\u4e0d\u76f8\u4ea4\u7684\u51f8\u591a\u8fb9\u5f62\u540c\u6837\u53ef\u505a\uff0c\u56e0\u4e3a\u6211\u4eec\u4f9d\u7136\u80fd\u8f83\u5feb\u7684\u6c42\u51fa\u4e0e\u626b\u63cf\u7ebf\u7684\u4ea4\u70b9\uff0c\u540c\u65f6\u4fdd\u6301\u51f8\u591a\u8fb9\u5f62\u7684\u76f8\u5bf9\u987a\u5e8f\u4e0d\u53d8\uff0c<del>\u53ea\u662f\u7ec6\u8282\u7a0d\u5fae\u591a\u4e00\u70b9<\/del>\u3002<\/p>\n<p>\u6211\u4eec\u4f9d\u7136\u9700\u8981\u5c06\u51f8\u591a\u8fb9\u5f62\u62c6\u6210\u4e0a\u4e0b\u4e24\u4e2a\u90e8\u5206\uff0c\u4e22\u5230 set \u91cc\u9762\u7ef4\u62a4\uff0c\u4e0d\u540c\u7684\u662f\uff0c\u6211\u4eec\u9700\u8981\u5c06\u6bcf\u6761\u8fb9\u90fd\u52a0\u5165\u626b\u63cf\u7ebf\uff0c\u4e00\u6761\u8fb9\u4e00\u6761\u8fb9\u7684\u626b\uff0c\u5e76\u5728 set \u91cc\u7ef4\u62a4\u8fd9\u4e9b\u8fb9\u7684\u76f8\u5bf9\u5173\u7cfb\u3002<\/p>\n<h3>\u5b9e\u73b0<\/h3>\n<p>\u5b9e\u73b0\u65b9\u5f0f\u76f8\u5bf9\u4e8e\u5706\u7684\u8fdb\u884c\u4e86\u4e00\u4e9b\u7b80\u5316\uff0c\u76f4\u63a5\u628a\u8fb9\u4e22\u5230 set \u91cc\u7ef4\u62a4\u4e86\u3002<\/p>\n<pre><code class=\"language-cpp\">#include &amp;lt;bits\/stdc++.h&amp;gt;\nusing namespace std;\ntypedef long long ll;\n#define int ll\nconst int maxn = 600050, mod = 998244353, INF = 1e9;\nconst double eps = 1e-9;\nint sweep_line_x = -1e9;\nvector&amp;lt;int&amp;gt; g[maxn];\nint fa[maxn];\n\nstruct Segment {\n    int id;\n    pair&amp;lt;int, int&amp;gt; p, q;\n    bool up_side;\n\n    Segment() {}\n    Segment(int id, pair&amp;lt;int, int&amp;gt; p, pair&amp;lt;int, int&amp;gt; q) : id(id), p(p), q(q)\n    {\n        if (p.first &amp;gt; q.first)up_side = true;\n        else up_side = false;\n    }\n    double get_y(int x) const {\n        if (p.first == q.first) return p.second;\n        return p.second + 1.0 * (x - p.first) * (q.second - p.second) \/ (q.first - p.first);\n    }\n\n    bool operator&amp;lt;(const Segment&amp;amp; rhs) const {\n        if (fabs(get_y(sweep_line_x) - rhs.get_y(sweep_line_x)) &amp;lt; eps) {\n            if (up_side == rhs.up_side) return q.first &amp;lt; rhs.q.first;\n            return up_side &amp;lt; rhs.up_side;\n        }\n        return get_y(sweep_line_x) + eps &amp;lt; rhs.get_y(sweep_line_x);\n    }\n};\n\nstruct Event {\n    int x;\n    Segment l;\n    bool is_left;\n    bool operator&amp;lt;(const Event&amp;amp; rhs) const {\n        if (x == rhs.x) {\n            if (is_left == rhs.is_left) return l.p.second &amp;gt; rhs.l.p.second;\n            return is_left &amp;gt; rhs.is_left;\n        }\n        return x &amp;lt; rhs.x;\n    }\n};\n\nsigned main() {\n    ios::sync_with_stdio(0);\n    int n;\n    cin &amp;gt;&amp;gt; n;\n\n    vector&amp;lt;Segment&amp;gt; p;\n    vector&amp;lt;Event&amp;gt; events;\n    for (int i = 1;i &amp;lt;= n;i++) {\n        int m;\n        cin &amp;gt;&amp;gt; m;\n        vector&amp;lt;pair&amp;lt;int, int&amp;gt;&amp;gt; tmp(m);\n        for (int j = 0;j &amp;lt; m;j++) {\n            cin &amp;gt;&amp;gt; tmp[j].first &amp;gt;&amp;gt; tmp[j].second;\n        }\n        for (int j = 0;j &amp;lt; m;j++) {\n            int k = (j + 1) % m;\n            if (tmp[j].first == tmp[k].first) continue;\n            p.push_back({ i, tmp[j], tmp[k] });\n        }\n    }\n    for (int i = 0; i &amp;lt; p.size(); i++) {\n        if (p[i].p.first &amp;gt; p[i].q.first) swap(p[i].p, p[i].q);\n        events.push_back({ p[i].p.first, p[i], true });\n        events.push_back({ p[i].q.first, p[i], false });\n    }\n\n    sort(events.begin(), events.end());\n\n    memset(fa,-1,sizeof fa);\n    set&amp;lt;Segment&amp;gt; s;\n\n    for (auto&amp;amp; [x, l, f] : events) {\n        sweep_line_x = x;\n        int id = l.id;\n        if (l.up_side and fa[id] == -1) {\n            auto it = s.upper_bound(l);\n            if (it != s.end()) {\n                Segment par = (*it);\n                if (par.up_side) fa[id] = par.id;\n                else fa[id] = fa[par.id];\n            }\n            else {\n                fa[id] = 0;\n            }\n            g[fa[id]].push_back(id);\n            g[id].push_back(fa[id]);\n        }\n        if (f == 1)s.insert(l);\n        else s.erase(l);\n    }\n\n    return 0;\n}<\/code><\/pre>\n<h3>\u4f8b\u9898<\/h3>\n<h4><a href=\"https:\/\/codeforces.com\/gym\/103388\/problem\/F\">Freedom from Prison<\/a><\/h4>\n<p>\u9898\u610f\uff1a\u7ed9\u51fa\u4e86\u5e73\u9762\u4e0a $n$ \u4e2a\u6ca1\u6709\u516c\u5171\u70b9\u7684\u51f8\u591a\u8fb9\u5f62\u3002\u5e73\u9762\u4e0a\u6709\u4e24\u4e2a\u70b9\uff0c\u4f60\u9700\u8981\u4ece\u5176\u4e2d\u4e00\u70b9\u8d70\u5230\u53e6\u4e00\u70b9\uff0c\u518d\u4ece\u8be5\u70b9\u8d70\u5230\u4e00\u4e2a\u4e0d\u88ab\u4efb\u4f55\u51f8\u591a\u8fb9\u5f62\u5305\u542b\u7684\u5730\u65b9\uff0c\u4ee3\u4ef7\u4e3a\u8def\u5f84\u4e0a\u7a7f\u8fc7\u7684\u51f8\u591a\u8fb9\u5f62\u8fb9\u754c\u6570\u91cf\u3002\u4f60\u53ef\u4ee5\u968f\u610f\u5b89\u6392\u4e24\u4e2a\u70b9\u7684\u4f4d\u7f6e\uff0c\u6c42\u4ee3\u4ef7\u7684\u6700\u5c0f\u503c\u6700\u5927\u662f\u591a\u5c11\u3002$n\\leq 10^5$\uff0c\u51f8\u591a\u8fb9\u5f62\u603b\u8fb9\u6570 $6\\times 10^5$\uff0c\u503c\u57df $10^9$\u3002<\/p>\n<p>\u8fd9\u9898\u5c31\u9700\u8981\u7528\u5230\u51f8\u591a\u8fb9\u5f62\u7684\u626b\u63cf\u7ebf\uff0c\u5c06\u51f8\u591a\u8fb9\u5f62\u4e4b\u95f4\u7684\u5305\u542b\u5173\u7cfb\u8f6c\u5316\u4e3a\u4e00\u9897\u6811\u3002\u8f6c\u5316\u4e3a\u6811\u4e4b\u540e\uff0c\u5c31\u662f\u6c42\u4ece\u6811\u4e0a\u4e00\u70b9\u8d70\u5230\u53e6\u4e00\u70b9\uff0c\u518d\u4ece\u8be5\u70b9\u8d70\u5230\u8d85\u7ea7\u6e90\u70b9\u7684\u8def\u5f84\u957f\u5ea6\u3002\u663e\u7136\uff0c\u7b54\u6848\u5c31\u662f\u4ece\u76f4\u5f84\u7684\u4e00\u7aef\u8d70\u5230\u53e6\u4e00\u7aef\uff0c\u518d\u8d70\u5230\u6811\u7684\u6839\u7684\u8def\u5f84\u957f\u5ea6\uff0c\u6c42\u4e2a\u76f4\u5f84\u5c31\u505a\u5b8c\u4e86\u3002<\/p>\n<pre><code class=\"language-cpp\">#include &amp;lt;bits\/stdc++.h&amp;gt;\nusing namespace std;\ntypedef long long ll;\n#define int ll\nconst int maxn = 600050, mod = 998244353, INF = 1e9;\nconst double eps = 1e-9;\nint sweep_line_x = -1e9;\nvector&amp;lt;int&amp;gt; g[maxn];\nint d, t;\nint fa[maxn];\n\nstruct Segment {\n    int id;\n    pair&amp;lt;int, int&amp;gt; p, q;\n    bool up_side;\n\n    Segment() {}\n    Segment(int id, pair&amp;lt;int, int&amp;gt; p, pair&amp;lt;int, int&amp;gt; q) : id(id), p(p), q(q)\n    {\n        if (p.first &amp;gt; q.first)up_side = true;\n        else up_side = false;\n    }\n    double get_y(int x) const {\n        if (p.first == q.first) return p.second;\n        return p.second + 1.0 * (x - p.first) * (q.second - p.second) \/ (q.first - p.first);\n    }\n\n    bool operator&amp;lt;(const Segment&amp;amp; rhs) const {\n        if (fabs(get_y(sweep_line_x) - rhs.get_y(sweep_line_x)) &amp;lt; eps) {\n            if (up_side == rhs.up_side) return q.first &amp;lt; rhs.q.first;\n            return up_side &amp;lt; rhs.up_side;\n        }\n        return get_y(sweep_line_x) + eps &amp;lt; rhs.get_y(sweep_line_x);\n    }\n};\n\nstruct Event {\n    int x;\n    Segment l;\n    bool is_left;\n    bool operator&amp;lt;(const Event&amp;amp; rhs) const {\n        if (x == rhs.x) {\n            if (is_left == rhs.is_left) return l.p.second &amp;gt; rhs.l.p.second;\n            return is_left &amp;gt; rhs.is_left;\n        }\n        return x &amp;lt; rhs.x;\n    }\n};\n\nvoid dfs(int x, int dep, int fath) {\n    if (dep &amp;gt; d) {\n        d = dep;\n        t = x;\n    }\n    for (int to : g[x]) {\n        if (to == fath)continue;\n        dfs(to, dep+1, x);\n    }\n}\n\nsigned main() {\n    ios::sync_with_stdio(0);\n    int n;\n    cin &amp;gt;&amp;gt; n;\n\n    vector&amp;lt;Segment&amp;gt; p;\n    vector&amp;lt;Event&amp;gt; events;\n    for (int i = 1;i &amp;lt;= n;i++) {\n        int m;\n        cin &amp;gt;&amp;gt; m;\n        vector&amp;lt;pair&amp;lt;int, int&amp;gt;&amp;gt; tmp(m);\n        for (int j = 0;j &amp;lt; m;j++) {\n            cin &amp;gt;&amp;gt; tmp[j].first &amp;gt;&amp;gt; tmp[j].second;\n        }\n        for (int j = 0;j &amp;lt; m;j++) {\n            int k = (j + 1) % m;\n            if (tmp[j].first == tmp[k].first) continue;\n            p.push_back({ i, tmp[j], tmp[k] });\n        }\n    }\n    for (int i = 0; i &amp;lt; p.size(); i++) {\n        if (p[i].p.first &amp;gt; p[i].q.first) swap(p[i].p, p[i].q);\n        events.push_back({ p[i].p.first, p[i], true });\n        events.push_back({ p[i].q.first, p[i], false });\n    }\n\n    sort(events.begin(), events.end());\n\n    memset(fa,-1,sizeof fa);\n    set&amp;lt;Segment&amp;gt; s;\n\n    for (auto&amp;amp; [x, l, f] : events) {\n        sweep_line_x = x;\n        int id = l.id;\n        if (l.up_side and fa[id] == -1) {\n            auto it = s.upper_bound(l);\n            if (it != s.end()) {\n                Segment par = (*it);\n                if (par.up_side) fa[id] = par.id;\n                else fa[id] = fa[par.id];\n            }\n            else {\n                fa[id] = 0;\n            }\n            g[fa[id]].push_back(id);\n            g[id].push_back(fa[id]);\n        }\n        if (f == 1)s.insert(l);\n        else s.erase(l);\n    }\n\n    dfs(0, 0, -1);\n    int st=t;\n    dfs(t, 0, -1);\n    int ans = d;\n\n    vector&amp;lt;int&amp;gt; dis(maxn,INF);\n    queue&amp;lt;int&amp;gt; q;\n    dis[0] = 0;\n    q.push(0);\n    while (!q.empty()){\n        int v = q.front();\n        q.pop();\n        for (auto const&amp;amp; to : g[v]){\n            if (dis[to] &amp;gt; dis[v] + 1){\n                dis[to] = dis[v] + 1;\n                q.push(to);\n            }\n        }\n    }\n    ans += max(dis[t], dis[st]);\n    cout &amp;lt;&amp;lt; ans &amp;lt;&amp;lt; &amp;#039;\\n&amp;#039;;\n\n    return 0;\n}<\/code><\/pre>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528\u626b\u63cf\u7ebf\u5c06\u5e73\u9762\u4e0a\u5706\u6216\u51f8\u591a\u8fb9\u5f62\u4e4b\u95f4\u7684\u5305\u542b\u5173\u7cfb\uff0c\u9ad8\u6548\u5730\u8f6c\u5316\u4e3a\u6811\u7ed3\u6784\uff08\u68ee\u6797\uff0c\u901a\u8fc7\u5f15\u5165\u8d85\u7ea7\u6e90\u70b9 $0$ \u8f6c\u5316\u4e3a\u4e00\u68f5\u6811\uff09\uff0c\u4ece\u800c\u5c06\u51e0\u4f55\u95ee\u9898\u8f6c\u5316\u4e3a\u6811\u4e0a\u95ee\u9898\uff0c\u6838\u5fc3\u601d\u60f3\u5c31\u662f\u5229\u7528\u56fe\u5f62\u4e4b\u95f4\u7684\u76f8\u5bf9\u5173\u7cfb\uff0c\u5c06\u56fe\u5f62\u62c6\u6210\u4e0a\u4e0b\u4e24\u90e8\u5206\uff0c\u5e76\u5728\u626b\u63cf\u7ebf\u8fc7\u7a0b\u4e2d\u4f7f\u7528 set \u7ef4\u62a4\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a $\\mathcal{O}(n \\log n)$\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5706\u7684\u626b\u63cf\u7ebf\u7b97\u6cd5 \u5f15\u5165 \u5e73\u9762\u4e0a\u6709 $n$ \u4e2a\u5706\uff0c\u5706\u4e4b\u95f4\u6ca1\u6709\u516c\u5171\u70b9\uff0c\u5373\u5706\u4e4b\u95f4\u8981\u4e48\u5305\u542b\uff0c\u8981\u4e48\u76f8\u79bb\u3002\u6b64\u65f6\u5706\u8981\u4e48\u90fd\u662f\u4e00\u4e2a [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,3,6],"tags":[],"class_list":["post-510","post","type-post","status-publish","format-standard","hentry","category-c","category-oi","category-6"],"_links":{"self":[{"href":"https:\/\/www.xgnd.net\/index.php\/wp-json\/wp\/v2\/posts\/510","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xgnd.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xgnd.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xgnd.net\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xgnd.net\/index.php\/wp-json\/wp\/v2\/comments?post=510"}],"version-history":[{"count":8,"href":"https:\/\/www.xgnd.net\/index.php\/wp-json\/wp\/v2\/posts\/510\/revisions"}],"predecessor-version":[{"id":560,"href":"https:\/\/www.xgnd.net\/index.php\/wp-json\/wp\/v2\/posts\/510\/revisions\/560"}],"wp:attachment":[{"href":"https:\/\/www.xgnd.net\/index.php\/wp-json\/wp\/v2\/media?parent=510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xgnd.net\/index.php\/wp-json\/wp\/v2\/categories?post=510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xgnd.net\/index.php\/wp-json\/wp\/v2\/tags?post=510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}