{"id":58080,"date":"2025-08-16T02:00:37","date_gmt":"2025-08-15T18:00:37","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/58080.html"},"modified":"2025-08-16T02:00:37","modified_gmt":"2025-08-15T18:00:37","slug":"%e5%8a%9b%e6%89%a3%e6%af%8f%e6%97%a5%e4%b8%80%e5%88%b7day-8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/58080.html","title":{"rendered":"\u529b\u6263\u6bcf\u65e5\u4e00\u5237Day 8"},"content":{"rendered":"<p>Practice Day eight:Leetcode T1584<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"597\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250815180030-689f75be8ef99.png\" width=\"805\" \/><\/p>\n<p>\u4e0a\u4e00\u6b21&#xff0c;\u6211\u4eec\u4f7f\u7528\u4e86Prim\u7b97\u6cd5\u89e3\u51b3\u4e86\u6700\u5c0f\u751f\u6210\u6811\u7684\u95ee\u9898&#xff0c;\u4e8b\u5b9e\u4e0aKruskal\u7b97\u6cd5\u4e5f\u662f\u89e3\u51b3\u6700\u5c0f\u751f\u6210\u6811\u7684\u4e00\u4e2a\u6709\u6548\u65b9\u6cd5\u3002\u6211\u4eec\u53ef\u4e0d\u80fd\u539a\u6b64\u8584\u5f7c&#xff0c;\u53ea\u8bb2\u89e3Prim\u7b97\u6cd5\u800c\u5bf9Kruskal\u7b97\u6cd5\u7f6e\u4e4b\u4e0d\u7406\u3002<\/p>\n<p>\u73b0\u5728&#xff0c;\u6211\u4eec\u5148\u6765\u8bb2\u89e3Kruskal\u7b97\u6cd5\u7684\u57fa\u672c\u539f\u7406:<\/p>\n<p>1 \u83b7\u53d6\u6240\u6709\u8282\u70b9\u8fde\u6210\u8fb9\u7684\u6570\u503c&#xff0c;\u5982\u679c\u6570\u503c\u4e3a0&#xff0c;\u76f4\u63a5\u7ec8\u6b62\u7a0b\u5e8f&#xff0c;\u8f93\u51fa\u7ed3\u679c\u3002\u5426\u5219&#xff0c;\u8fdb\u5165\u4e0b\u4e00\u6b65\u64cd\u4f5c\u3002<\/p>\n<p>2 \u4ee5\u4ece\u5927\u5230\u5c0f&#xff0c;\u597d\u5427&#xff0c;\u5176\u5b9e\u4ece\u5c0f\u5230\u5927\u4e5f\u884c&#xff0c;\u603b\u4e4b&#xff0c;\u7ed9\u4ed6\u4eec\u6392\u5e8f<\/p>\n<p>3 \u9009\u53d6\u5176\u4e2d\u6700\u5c0f\u7684\u8fb9<\/p>\n<p>4 \u5224\u65ad\u8fd9\u6761\u8fb9\u88ab\u5b9e\u88c5\u540e&#xff0c;\u662f\u5426\u4f1a\u5f62\u6210\u591a\u4e2a\u8fde\u901a\u5206\u91cf&#xff0c;\u7528\u4eba\u8bdd\u8bf4&#xff0c;\u5c31\u662f\u662f\u5426\u4f1a\u6210\u73af<\/p>\n<p>5 \u6210\u73af&#xff1a;\u90a3\u5c31\u6eda\u86cb&#xff0c;\u6211\u4eec\u8981\u6700\u5c0f\u751f\u6210\u6811&#xff0c;\u6210\u73af\u663e\u7136\u4e0d\u7b26\u5408\u6211\u4eec\u7684\u6807\u51c6\u3002<\/p>\n<p>\u4e0d\u6210\u73af&#xff1a;\u4f60\u8fc7\u5173\u3002\u5b9e\u88c5\u8fd9\u6761\u8fb9\u3002<\/p>\n<p>6 \u5224\u65ad\u6b64\u65f6\u6240\u6709\u8282\u70b9\u662f\u5426\u5df2\u7136\u88ab\u94fe\u63a5\u3002\u82e5\u5df2\u7136\u5b8c\u5168\u94fe\u63a5&#xff0c;\u7ec8\u6b62\u7a0b\u5e8f\u3002\u82e5\u672a\u94fe\u63a5\u5168\u90e8\u8282\u70b9&#xff0c;\u5219\u5faa\u73af\u6b65\u9aa43&#xff0c;4&#xff0c;5&#xff0c;6<\/p>\n<p>\u5b8c\u6210\u5bf9Kruskal\u7b97\u6cd5\u7684\u521d\u6b65\u4e86\u89e3\u540e&#xff0c;\u6211\u4eec\u6765\u770b\u770b\u9898\u76ee\u8981\u6c42&#xff1a;\u5f97\u5230\u6700\u5c0f\u751f\u6210\u6811\u3002<\/p>\n<p>\u6ca1\u4ec0\u4e48\u597d\u8bf4\u7684&#xff0c;\u5c31\u7528Kruksal\u7b97\u6cd5\u3002<\/p>\n<p>\u4f46\u662f\u9898\u76ee\u8fd9\u4e2a\u56fe&#xff0c;\u6bd4\u8f83\u6709\u610f\u601d\u7684\u662f&#xff0c;\u4ed6\u662f\u4ee5\u5750\u6807\u7684\u5f62\u5f0f\u7ed9\u51fa\u4f4d\u7f6e\u7684&#xff0c;\u5e76\u4e0d\u662f\u76f4\u63a5\u628a\u4e00\u4e2a\u8fde\u901a\u56fe\u7684\u6743\u91cd\u544a\u8bc9\u4f60\u3002<\/p>\n<p>\u6211\u60f3\u8bf4\u7684\u662f&#xff0c;\u8fd9\u6837\u4e00\u6765&#xff0c;\u6211\u4eec\u7684\u64cd\u4f5c\u7a7a\u95f4\u5c31\u53d8\u5927\u4e86\u3002\u4e3a\u4ec0\u4e48\u8fd9\u4e48\u8bf4&#xff1f;\u56e0\u4e3a\u6211\u4eec\u83b7\u5f97\u4e86\u4e00\u4e2a\u65b0\u7684\u4fe1\u606f&#xff1a;\u89d2\u5ea6\u3002<\/p>\n<p>\u82e5\u662f\u5355\u7eaf\u7ed9\u51fa\u4e00\u4e2a\u65e0\u5411\u94fe\u63a5\u56fe\u7ed9\u4f60&#xff0c;\u4f60\u53ea\u80fd\u77e5\u9053\u5404\u4e2a\u8282\u70b9\u4e4b\u95f4\u7684\u6743\u91cd&#xff0c;\u4f60\u53ea\u6709\u8fd9\u4e2a\u4fe1\u606f\u3002<\/p>\n<p>\u4f46\u662f\u4ee5\u5750\u6807\u5f62\u5f0f\u7ed9\u51fa&#xff0c;\u4f60\u5c31\u53ef\u4ee5\u83b7\u77e5&#xff1a;\u8282\u70b9\u4e4b\u95f4\u7684\u6743\u91cd\u3001\u6743\u91cd\u95f4\u7684\u5939\u89d2<\/p>\n<p>\u6765\u601d\u8003\u4e00\u4e0b&#xff0c;\u8fd9\u4e2a\u5939\u89d2&#xff0c;\u4ed6\u786e\u5b9e\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u7b80\u5316\u4ee3\u7801\u5417&#xff1f;<\/p>\n<p>\u66f4\u591a\u65f6\u5019&#xff0c;\u589e\u52a0\u4e00\u4e2a\u5f71\u54cd\u56e0\u7d20&#xff0c;\u4ed6\u5f80\u5f80\u4f1a\u8ba9\u4e8b\u60c5\u53d8\u5f97\u66f4\u590d\u6742&#xff0c;\u8fd9\u91cc\u4e5f\u4e0d\u5217\u5916\u3002<\/p>\n<p>\u4f46\u662f&#xff0c;\u53ef\u4ee5\u8ba9\u6211\u4eec\u7684\u7a0b\u5e8f\u66f4\u52a0\u5feb\u901f&#xff01;\u54c8\u54c8\u54c8\u54c8&#xff01;<\/p>\n<p>\u6765\u770b\u770b\u8fd9\u662f\u600e\u4e48\u4e00\u56de\u4e8b\u5427&#xff01;<\/p>\n<p>\u867d\u7136Kruskal\u7b97\u6cd5\u7684\u6838\u5fc3\u662f\u4ee5\u8fb9\u4e3a\u57fa\u7840\u5c55\u5f00\u7684&#xff0c;\u6240\u4ee5&#xff0c;\u6211\u4eec\u53ef\u4ee5\u5f88\u8f7b\u6613\u7684\u77e5\u9053&#xff0c;\u5f53\u8fb9\u8d8a\u591a&#xff0c;\u8d8a\u590d\u6742\u7684\u65f6\u5019&#xff0c;\u7b97\u6cd5\u5b9e\u73b0\u65f6\u95f4\u4f1a\u53d8\u5f97\u5f88\u957f\u3002\u5bf9\u4e8e\u8fd9\u7c7b\u56fe&#xff0c;\u6211\u4eec\u7ba1\u4ed6\u53eb\u7a20\u5bc6\u56fe\u3002<\/p>\n<p>\u5bf9\u4e8e\u7a20\u5bc6\u56fe&#xff0c;\u6211\u4eec\u66f4\u559c\u6b22\u7528Prim\u7b97\u6cd5\u8fdb\u884c\u89e3\u51b3\u3002\u56e0\u4e3aPrim\u7b97\u6cd5\u662f\u4ee5\u70b9\u4e3a\u57fa\u7840\u7684&#xff0c;\u8fb9\u7684\u591a\u4e0e\u5be1&#xff0c;\u5b9e\u9645\u5bf9\u7b97\u6cd5\u7684\u5b9e\u73b0\u7684\u65f6\u95f4\u5f71\u54cd\u5e76\u4e0d\u5927\u3002<\/p>\n<p>\u4e8b\u5b9e\u4e0a&#xff0c;Kruskal\u66f4\u9002\u5408\u89e3\u51b3\u8fb9\u66f4\u5c11\u7684\u7a00\u758f\u56fe&#xff0c;\u4ed6\u5728\u7a00\u758f\u56fe\u4e0a\u89e3\u51b3\u95ee\u9898\u7684\u65f6\u95f4\u8fdc\u6bd4Prim\u7b97\u6cd5\u597d\u5f97\u591a\u3002\u533a\u5206\u7a20\u5bc6\u56fe\u548c\u7a00\u758f\u56fe\u7684\u4e34\u754c\u6761\u4ef6&#xff0c;\u5c31\u662f\u8fb9\u7684\u6570\u76ee\u63a5\u8fd1n^2\/2\u3002<\/p>\n<p>\u8fd9\u65f6\u4f60\u53ef\u80fd\u5bdf\u89c9\u51fa\u95ee\u9898\u6240\u5728\u4e86&#xff1a;\u9898\u76ee\u53ea\u7ed9\u4e86\u5750\u6807&#xff0c;\u5de6\u8fb9\u4e24\u4e24\u76f8\u8fde\u53ef\u662f\u6709n&#xff08;n-1&#xff09;\/2\u6761\u8fb9&#xff0c;\u8fd9\u6beb\u65e0\u7591\u95ee\u662f\u7a20\u5bc6\u56fe&#xff0c;Kruskal\u7b97\u6cd5\u5b8c\u5168\u4e0d\u9002\u7528\u4e8e\u8fd9\u4e2a\u9898\u76ee\u3002<\/p>\n<p>\u6ca1\u6709Prim\u5927\u4eba\u7684\u529b\u91cf&#xff0c;\u6211\u4eec\u8be5\u5982\u4f55\u6218\u80dc\u7a20\u5bc6\u56fe&#xff1f;&#xff01;<\/p>\n<p>\u4f5c\u8005\u6de1\u7136\u4e00\u7b11&#xff0c;\u4e00\u628a\u6293\u4f4f\u7a20\u5bc6\u56fe&#xff0c;\u9877\u523b\u70bc\u5316&#xff01;<\/p>\n<p>\u6211\u5c31\u662f\u975e\u5f97\u8981\u7528Kruskal&#xff0c;\u4e3a\u4ec0\u4e48\u975e\u8981\u7b97\u6cd5\u9002\u5e94\u9898\u76ee&#xff1f;\u6211\u5b8c\u5168\u53ef\u4ee5\u6539\u9020\u9898\u76ee&#xff0c;\u8ba9\u4ed6\u53d8\u5f97\u9002\u5e94\u7b97\u6cd5&#xff01;<\/p>\n<p>\u8fd9\u65f6\u5019\u5c31\u9700\u8981\u7528\u5230\u5f3a\u5927\u7684\u51e0\u4f55\u6b66\u5668\u4e86&#xff01;<\/p>\n<p>\u5728\u4e00\u4e2a\u5e73\u9762\u4e09\u89d2\u5f62\u4e2d&#xff1a;<\/p>\n<p>\u53e4\u8bed\u6709\u66f0&#xff1a;\u5927\u89d2\u5bf9\u5927\u8fb9\u3002<\/p>\n<p>\u7b80\u800c\u8a00\u4e4b&#xff0c;\u5c31\u662f\u89d2\u8d8a\u5927&#xff0c;\u8fb9\u5c31\u8d8a\u5927\u3002\u8fd9\u4e2a\u53ef\u4ee5\u901a\u8fc7\u4f59\u5f26\u5b9a\u7406\u4e25\u683c\u8bc1\u660e\u3002\u53cd\u6b63\u4f60\u9ad8\u4e2d\u5b66\u8fc7\u4e86&#xff0c;\u5bf9\u5427&#xff1f;<\/p>\n<p>\u6784\u6210\u4e00\u4e2a\u4e09\u89d2\u5f62&#xff0c;\u6211\u4eec\u9700\u8981\u4e09\u4e2a\u9876\u70b9&#xff0c;\u600e\u4e48\u6392\u5217\u90fd\u53ef\u4ee5\u3002<\/p>\n<p>\u6211\u4eec\u77e5\u9053&#xff0c;\u82e5\u60f3\u8fde\u540c\u4e09\u4e2a\u70b9&#xff0c;\u5b9e\u9645\u4e0a\u6211\u4eec\u53ea\u9700\u9009\u62e9\u4e09\u6761\u8fb9\u4e2d\u7684\u5176\u4e2d\u4e24\u6761\u5373\u53ef\u3002<\/p>\n<p>\u82e5\u662f\u9700\u8981\u6700\u5c0f\u751f\u6210\u6811&#xff0c;\u5219\u80af\u5b9a\u4e0d\u80fd\u9009\u5176\u4e2d\u6700\u5927\u7684\u8fd9\u6761\u8fb9\u3002<\/p>\n<p>\u8fd9\u6837&#xff0c;\u6211\u4eec\u5c31\u901a\u8fc7\u51e0\u4f55\u5173\u7cfb&#xff0c;\u51cf\u5c11\u4e86\u53ef\u4ee5\u9009\u62e9\u7684\u8fb9&#xff0c;\u7a20\u5bc6\u56fe&#xff0c;\u6e10\u6e10\u53d8\u6210\u4e86\u7a00\u758f\u56fe\u3002<\/p>\n<p>\u5f88\u660e\u4e86\u4e86&#xff0c;\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u3010\u89d2\u5ea6\u3011\u6765\u9009\u62e9\u8fb9\u3002<\/p>\n<p>\u600e\u4e48\u5e94\u7528\u4ed6&#xff1f;\u8fd9\u597d\u50cf\u5f88\u9ebb\u70e6\u6b38&#xff1f;\u5939\u89d2\u662f\u76f8\u5bf9\u800c\u8a00\u7684&#xff0c;\u4e5f\u5c31\u662f\u8bf4&#xff0c;\u5982\u679c\u6211\u8981\u4f7f\u7528\u5939\u89d2\u8fd9\u4e2a\u4fe1\u606f&#xff0c;\u6211\u4e0d\u80fd\u5b64\u7acb\u7684\u4f7f\u7528\u5b83&#xff0c;\u6211\u4eec\u5fc5\u987b\u6709\u4e24\u6761\u8fb9\u624d\u80fd\u4f7f\u7528\u4ed6\u3002<\/p>\n<p>\u5c31\u7b97\u77e5\u9053\u4e86\u8fb9\u957f&#xff0c;\u6211\u4eec\u4ecd\u9700\u901a\u8fc7\u4e09\u89d2\u5f62\u7684\u4f59\u5f26\u5b9a\u7406\u624d\u80fd\u77e5\u9053\u89d2\u5ea6&#xff0c;md&#xff0c;\u8fd9\u4e0d\u662f\u6ca1\u4e8b\u627e\u4e8b\u5417&#xff0c;\u6211\u8981\u77e5\u9053\u957f\u5ea6\u4e86&#xff0c;\u8fd8\u8981\u4ec0\u4e48\u89d2\u5ea6\u3002<\/p>\n<p>\u6240\u4ee5\u89d2\u5ea6\u7684\u5e94\u7528\u65b9\u5f0f\u4e0d\u662f\u8fd9\u6837\u7684&#xff0c;\u6211\u4eec\u5982\u679c\u80fd\u627e\u5230\u4e00\u4e2a\u7279\u6b8a\u7684\u89d2\u5ea6&#xff0c;\u8ba9\u4ed6\u548c\u8fb9\u5bf9\u5e94\u8d77\u6765&#xff0c;\u90a3\u8be5\u6709\u591a\u597d\u3002\u8fb9&#xff0c;\u5b9e\u9645\u4e0a\u53c8\u662f\u5750\u6807\u7684\u4e8c\u7ea7\u4ea7\u7269&#xff0c;\u800c\u9898\u76ee\u53c8\u662f\u4ee5\u5750\u6807\u7684\u5f62\u5f0f\u7ed9\u51fa&#xff0c;\u8981\u6c42\u6211\u4eec\u8ba1\u7b97\u7684\u662f\u66fc\u54c8\u987f\u8ddd\u79bb&#xff0c;\u800c\u4e0d\u662f\u5b9e\u9645\u610f\u4e49\u4e0a\u7684\u8fb9\u957f&#xff0c;\u90a3\u6211\u4eec\u4e3a\u4ec0\u4e48\u4e0d\u76f4\u63a5\u4ee5\u66fc\u54c8\u987f\u8ddd\u79bb\u7684\u5f62\u5f0f\u6765\u7b49\u6548\u5904\u7406\u8fd9\u4e2a\u8fb9\u957f\u5462&#xff1f;\u6bd5\u7adf\u8fb9\u957f\u7684\u5927\u5c0f\u5b9e\u9645\u4e0a\u4e0e\u66fc\u54c8\u987f\u8ddd\u79bb&#xff08;\u5b9e\u9645\u5e94\u63cf\u8ff0\u4e3a\u6a2a\u5411\u8ddd\u79bb\u548c\u7eb5\u5411\u8ddd\u79bb&#xff09;\u662f\u4e00 \u4e00\u5bf9\u5e94\u7684\u3002<\/p>\n<p>\u7b54\u6848\u5df2\u7ecf\u5f88\u660e\u663e\u4e86&#xff01;\u806a\u660e\u7684\u4f60\u5df2\u7ecf\u60f3\u5230&#xff0c;\u8fd9\u4e2a\u89d2\u5ea6&#xff0c;\u4ed6\u5c31\u662f45\u00b0&#xff0c;\u53ea\u6709\u4ed6&#xff0c;\u624d\u53ef\u4ee5\u5f88\u8f7b\u6613\u7684\u628a\u6a2a\u7eb5\u5750\u6807\u7ed9\u7b80\u5355\u8054\u7cfb\u8d77\u6765&#xff0c;\u56e0\u4e3a\u8fd9\u662f\u4e00\u4e2a\u53ef\u4ee5\u901a\u8fc7\u6570\u503c\u7b80\u5355\u4e8c\u5206\u7c7b\u7684\u6a21\u578b&#xff0c;\u82e5\u6a2a\u5411\u8ddd\u79bb\u4e0e\u7eb5\u5411\u8ddd\u79bb\u76f8\u7b49&#xff0c;\u90a3\u5c31\u662f45\u00b0&#xff0c;\u82e5\u4e0d\u7b49&#xff0c;\u5c31\u4e0d\u662f45\u00b0&#xff0c;\u5b8c\u5168\u4e0d\u9700\u8981\u8fdb\u884c\u522b\u7684\u5904\u7406\u3002<\/p>\n<p>\u5148\u501f\u529b\u6263\u5b98\u65b9\u7684\u56fe\u7528\u4e00\u4e0b<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"341\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250815180032-689f75c0e7917.png\" width=\"345\" \/><\/p>\n<p>\u518d\u7ed3\u5408\u6211\u4eec\u524d\u9762\u7684\u7406\u8bba&#xff0c;\u6211\u4eec\u53ef\u4ee5\u5f97\u77e5&#xff0c;45\u00b0\u5bf9\u5e94\u7684\u89d2\u4e00\u5b9a\u4e0d\u4f1a\u662f\u6700\u5927\u89d2&#xff0c;\u4e5f\u5c31\u662f&#xff0c;\u8fd9\u4e2a\u89d2\u6240\u5bf9\u8fb9\u4e00\u5b9a\u4e0d\u662f\u6700\u5927\u8fb9&#xff0c;\u8fd9\u5c31\u5f3a\u8feb\u6211\u4eec\u5fc5\u987b\u8981\u5728\u7b80\u5355\u8ba1\u7b97\u5c31\u77e5\u9053\u4e86&#xff0c;\u4e0d\u518d\u8fc7\u591a\u63cf\u8ff0\u3002<\/p>\n<p>\u53ef\u4ee5\u770b\u5230&#xff0c;\u6574\u4e2a\u5e73\u9762&#xff0c;\u88ab\u6211\u4eec\u5206\u4e3a\u4e86\u516b\u4e2a\u90e8\u5206\u3002\u73b0\u5728&#xff0c;\u6211\u4eec\u5c31\u53ef\u4ee5\u5206\u533a\u57df\u8fdb\u884c\u5904\u7406\u4e86\u3002<\/p>\n<p>1\u00a0\u4ee5\u9009\u4e2d\u7684\u8282\u70b9\u4f5c\u4e3a\u539f\u70b9&#xff0c;\u5b9e\u73b0\u8fd9\u4e2a\u975e\u5e38\u7b80\u5355&#xff0c;\u53ea\u9700\u8981\u628a\u4e24\u4e2a\u8282\u70b9\u7684\u5750\u6807\u76f8\u51cf\u5373\u53ef&#xff0c;\u8fd9\u76f8\u5f53\u4e8e\u5e73\u79fb\u5750\u6807\u7cfb&#xff0c;\u73b0\u5728&#xff0c;\u6211\u4eec\u7ba1\u8fd9\u4e2a\u5904\u4e8e\u539f\u70b9\u5750\u6807\u53eb\u505aa<\/p>\n<p>2 \u6211\u4eec\u5148\u4ee5P1\u533a\u4e3a\u4f8b&#xff0c;\u6211\u4eec\u518d\u968f\u4fbf\u53d6\u4e00\u4e2a\u5750\u6807&#xff0c;\u4e5f\u8bb8\u6ca1\u8fd9\u4e48\u5e78\u8fd0&#xff0c;\u4e00\u4e0b\u5c31\u53d6\u5230\u4e86P1\u533a&#xff0c;\u6211\u7ba1\u4ed6\u53ebb<\/p>\n<p>3 \u6211\u4eec\u5982\u4f55\u5224\u5b9a&#xff0c;b\u4ed6\u786e\u5b9e\u5728P1\u533a\u95f4\u91cc\u9762\u5462&#xff1f;\u518d\u8fdb\u4e00\u6b65&#xff0c;\u8fd9\u4e2aP1\u533a\u5230\u5e95\u662f\u600e\u4e48\u5212\u5206\u7684\u5462&#xff1f;\u6211\u4eec\u77e5\u9053&#xff0c;P1\u533a\u4e0d\u8fc7\u662fa\u70b9\u7684\u5f15\u7533&#xff0c;\u6240\u4ee5\u5bf9\u4e8e\u533a\u57df\u5212\u5206\u7684\u95ee\u9898&#xff0c;\u6211\u4eec\u9700\u8981\u4ecea\u70b9\u5165\u624b\u3002<\/p>\n<p>4 \u6211\u4eec\u77e5\u9053&#xff0c;\u5bf9\u4e8e45\u00b0&#xff0c;\u5176\u659c\u7387\u4e3aK&#061;1&#xff0c;\u4e5f\u5c31\u662f\u8bf4&#xff0c;\u5bf9\u4e8e\u6070\u597d\u5904\u4e8e\u70b9a\u768445\u00b0\u65b9\u5411\u7684\u70b9&#xff08;\u6ce8\u610f&#xff0c;\u8fd9\u91cc\u63cf\u8ff0\u7684\u4e0d\u662f\u5904\u4e8eP1\u533a\u57df\u7684\u70b9&#xff09;&#xff0c;\u5e94\u8be5\u6ee1\u8db3Xz-Xa&gt;0\u00a0 \u8fd9\u662f\u4e3a\u4e86\u4fdd\u8bc1b\u5728a\u7684\u53f3\u534a\u533a\u95f4\u00a0 \u00a0 \u00a0 \u00a0 \u00a0<\/p>\n<p>Yz-Xz&#061;Ya-Xa\u00a0 \u00a0 \u8fd9\u662f\u56e0\u4e3a\u5904\u4e8ea\u7684P1\u533a\u57df\u7684\u70b9&#xff0c;\u5e94\u8be5\u6ee1\u8db3\u65b9\u7a0b\u5f0fY-X&#061;C(C\u662f\u4e00\u4e2a\u5e38\u6570&#xff0c;\u8868\u793a\u5bf9\u4ee5\u539f\u70b9\u51fa\u53d1\u768445\u00b0\u7684\u6821\u6b63\u6570\u503c&#xff0c;\u6bd5\u7adf\u4e0d\u7ba1\u600e\u4e48\u8bf4&#xff0c;\u6211\u4eec\u768445\u00b0\u4ecd\u7136\u4ee5\u771f\u6b63\u7684\u539f\u70b9\u53ca\u5176\u5750\u6807\u7cfb\u4e3a\u6807\u51c6&#xff09;<\/p>\n<p>5 \u90a3\u4e48&#xff0c;\u5f88\u6e05\u6670\u4e86&#xff0c;\u82e5\u662f\u70b9b\u5904\u4e8eP1\u533a\u57df&#xff0c;\u5c31\u5e94\u8be5\u6ee1\u8db3Xb-Xa&gt;0&#xff0c;\u4ee5\u53caYb-Xb&gt;C<\/p>\n<p>6 \u5728\u5b8c\u6210\u533a\u57df\u7684\u5224\u522b\u4e4b\u540e&#xff0c;\u6211\u4eec\u5c31\u9700\u8981\u8fdb\u884c\u6700\u77ed\u8fb9\u7684\u5224\u65ad\u3002\u6211\u4eec\u77e5\u9053&#xff0c;\u5bf9\u4e8e\u5904\u4e8eP1\u533a\u57df\u7684\u70b9\u800c\u8a00&#xff0c;\u66fc\u54c8\u987f\u8ddd\u79bb\u53ef\u4ee5\u88ab\u8868\u793a\u4e3aD&#061;&#xff08;Xz-Xa&#xff09;&#043;&#xff08;Yz-Ya&#xff09;&#061;&#xff08;Xz&#043;Yz&#xff09;-&#xff08;Xa&#043;Ya&#xff09;&#xff0c;\u6709\u610f\u601d\u7684\u662f&#xff0c;Xa&#043;Ya\u5728\u6b64\u5904\u5b9e\u9645\u4e0a\u662f\u4e2a\u5b9a\u503c&#xff0c;\u5728\u5904\u7406\u7684\u8fc7\u7a0b\u4e2d&#xff0c;\u4f1a\u6539\u53d8\u7684\u53ea\u6709Xz&#043;Yz\u3002\u4e5f\u5c31\u662f\u8bf4&#xff1a;&#xff08;Xz&#043;Yz&#xff09;\u8d8a\u5927&#xff0c;\u66fc\u54c8\u987f\u8ddd\u79bb\u5c31\u8d8a\u5927<\/p>\n<p>7 \u90a3\u4e48&#xff0c;\u5bf9\u4e8e\u66fc\u54c8\u987f\u8ddd\u79bb\u7684\u5224\u65ad&#xff0c;\u5c31\u7b80\u5316\u4e3a\u4e86\u5bf9\u6240\u9009\u8282\u70b9&#xff08;Xz&#043;Yz&#xff09;\u503c\u7684\u5224\u65ad&#xff0c;\u8fd9\u4e2a\u503c\u53ef\u4e0d\u4f1a\u56e0\u4e3a\u53c2\u8003\u7cfb\u7684\u6539\u53d8\u800c\u6539\u53d8&#xff0c;\u51cf\u5c11\u4e86\u6211\u4eec\u5927\u91cf\u7684\u5b58\u50a8\u5de5\u4f5c\u4e0e\u5b58\u50a8\u7a7a\u95f4&#xff0c;\u5e76\u4e14\u8fd9\u4e2a\u662f\u6bcf\u4e00\u4e2a\u8282\u70b9\u72ec\u6709\u7684\u503c<\/p>\n<p>8 \u8bb0\u5f55\u5904\u4e8eP1\u533a\u57df\u7684\u6240\u6709\u503c&#xff0c;\u901a\u8fc7\u4e8c\u53c9\u641c\u7d22\u6811&#xff08;BIT&#xff09;&#xff0c;\u9009\u51fa\u5176\u4e2d\u7684\u6700\u5c0f\u503c&#xff0c;\u653e\u5165\u961f\u5217&#xff0c;\u4fdd\u7559\u4ed6\u3002<\/p>\n<p>9 \u90a3\u4e48\u5269\u4e0b\u7684P2&#xff0c;P3&#xff0c;P4\u4e5f\u662f\u540c\u6837\u7684\u64cd\u4f5c&#xff0c;\u8bb0\u5f55\u4e0b\u672c\u533a\u95f4\u7684\u6700\u5c0f\u503c\u3002\u4e3a\u4ec0\u4e48\u4e0d\u628a\u5de6\u4fa7\u4e5f\u4e00\u8d77\u8ba1\u7b97\u4e86&#xff0c;\u4e3a\u4ec0\u4e48\u53ea\u8ba1\u7b97\u53f3\u4fa7&#xff1f;\u56e0\u4e3a\u8fd9\u6837\u5c31\u4f1a\u9020\u6210\u91cd\u590d\u3002\u6765\u60f3\u4e00\u60f3\u5427&#xff01;\u6211\u4eec\u662f\u9700\u8981\u5bf9\u6240\u6709\u8282\u70b9\u90fd\u8fdb\u884c\u8fd9\u4e2a\u64cd\u4f5c\u7684&#xff01;\u8fd9\u610f\u5473\u7740\u4ec0\u4e48&#xff1f;&#xff01;<\/p>\n<p>10 \u610f\u5473\u7740&#xff0c;\u5904\u4e8e\u6700\u5de6\u4fa7\u7684\u8282\u70b9\u4e00\u5b9a\u4f1a\u88ab\u9009\u4e2d&#xff01;\u53ea\u8981\u4ed6\u88ab\u9009\u4e2d&#xff0c;\u5c31\u610f\u5473\u7740\u9664\u4e86\u4ed6\u4e4b\u5916\u7684\u8282\u70b9\u5c31\u4e00\u5b9a\u4f1a\u4e0e\u4ed6\u4ea7\u751f\u8054\u7cfb&#xff0c;\u56e0\u4e3a\u6211\u4eec\u7684\u8ba1\u7b97\u6d41\u7a0b\u5c31\u662f\u8fd9\u4e48\u8bbe\u8ba1\u7684&#xff0c;\u7531\u4e8e\u8fd9\u662f\u4e00\u4e2a\u65e0\u5411\u56fe&#xff0c;\u63cf\u8ff0\u4e3aa\u4e0eb\u8fde\u63a5&#xff0c;\u4e0e\u63cf\u8ff0\u4e3ab\u4e0ea\u8fde\u63a5&#xff0c;\u5b9e\u9645\u4e0a\u5730\u4f4d\u662f\u7b49\u4ef7\u7684&#xff0c;a\u7684\u53f3\u4fa7&#xff0c;\u5b9e\u9645\u4e0a\u5c31\u662fb\u7684\u5de6\u4fa7&#xff0c;\u53ea\u4e0d\u8fc7\u4e3b\u4f53\u4e0d\u540c&#xff0c;\u63cf\u8ff0\u65b9\u5f0f\u4e0d\u540c\u800c\u5df2&#xff1a;\u6211\u7684\u8fb9&#xff0c;\u5c31\u662f\u4f60\u7684\u8fb9<\/p>\n<p>11 \u6240\u4ee5&#xff0c;\u6211\u4eec\u53ea\u9700\u8981\u8ba1\u7b97\u4e00\u4fa7&#xff0c;\u5c31\u8db3\u4ee5\u8ba1\u7b97\u6240\u6709\u8282\u70b9\u4e4b\u95f4\u7684\u8054\u7cfb\u4e86&#xff0c;\u5982\u679c\u5168\u65b9\u4f4d\u8fdb\u884c\u8ba1\u7b97&#xff0c;\u5c31\u4f1a\u6d6a\u8d39\u8ba1\u7b97\u8d44\u6e90&#xff0c;\u6ca1\u6709\u8fd9\u4e2a\u5fc5\u8981<\/p>\n<p>12 \u4e00\u4e2a\u8282\u70b9&#xff0c;\u6700\u591a\u5f15\u7533\u51fa\u516b\u6761\u8fb9\u4e0e\u5176\u4ed6\u8282\u70b9\u8fde\u63a5&#xff0c;\u56e0\u4e3a\u6bcf\u4e2a\u533a\u57df&#xff0c;\u53ea\u6709\u4e00\u6761\u6700\u77ed\u8fb9\u3002\u8fd9\u5f53\u7136\u4e0d\u662f\u4ec0\u4e48\u4e8c\u7ea7\u7ed3\u8bba&#xff0c;\u8fd9\u53ea\u662f\u6211\u4eec\u7531\u533a\u57df\u5212\u5206\u800c\u5f97\u51fa\u6765\u7684\u6570\u5b57\u3002<\/p>\n<p>13 \u6b38&#xff0c;\u6709\u4eba\u53ef\u80fd\u4f1a\u8bf4&#xff1a;\u4f60\u600e\u4e48\u8bc1\u660e\u8fd9\u516b\u6761\u8fb9\u80af\u5b9a\u80fd\u8fde\u63a5\u6240\u6709\u8282\u70b9&#xff1f;\u5176\u5b9e\u4f60\u53ef\u4ee5\u8fd9\u6837\u60f3&#xff1a;\u5176\u5b9e&#xff0c;\u8fd9\u5c31\u662f\u6bcf\u4e2a\u8282\u70b9\u81ea\u53d1\u7684\u627e\u79bb\u81ea\u5df1\u6700\u8fd1\u7684\u8282\u70b9\u3002\u867d\u7136\u8fd9\u6709\u8fddKruskal\u7b97\u6cd5\u7684\u601d\u60f3&#xff0c;\u53cd\u800c\u4e0ePrim\u7b97\u6cd5\u7684\u601d\u60f3\u66f4\u63a5\u8fd1&#xff0c;\u4f46\u5b9e\u9645\u4e0a&#xff0c;\u7b5b\u67e5\u7684\u65f6\u5019\u6211\u4eec\u5229\u7528\u7684\u662fKruskal\u7b97\u6cd5&#xff0c;\u6240\u4ee5\u4ed6\u662f\u5f53\u4e4b\u65e0\u6127\u7684Kruskal\u7b97\u6cd5\u3002<\/p>\n<p>13 \u6211\u4eec\u5b8c\u6210\u4e86\u5bf9\u8fb9\u7684\u51cf\u5c11\u540e &#xff0c;\u8fd9\u5b8c\u5168\u5c31\u662f\u4e00\u4e2a\u7a00\u758f\u56fe\u4e86\u3002\u628a\u8fd9\u4e9b\u7b5b\u9009\u540e\u7684\u8fb9\u6254\u8fdb\u961f\u5217\u4e2d&#xff0c;\u7136\u540e\u4e3a\u4ed6\u4eec\u6392\u5e8f\u3002<\/p>\n<p>14 \u53d6\u51fa\u6700\u5c0f\u8fb9&#xff0c;\u5224\u65ad\u5b83\u662f\u5426\u6210\u73af&#xff0c;\u8fd9\u4e00\u70b9&#xff0c;\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5e76\u67e5\u96c6\u6765\u5b9e\u73b0&#xff0c;\u53ea\u9700\u8981\u5224\u65ad\u5176\u662f\u5426\u5c5e\u4e8e\u540c\u4e00\u4e2a\u7236\u8282\u70b9\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<p>15 \u6210\u73af&#xff1a;\u820d\u5f03&#xff0c;\u9009\u53d6\u4e0b\u4e00\u6761\u8fb9\u957f\u7ee7\u7eed\u5de5\u4f5c<\/p>\n<p>\u00a0\u4e0d\u6210\u73af&#xff1a;\u9009\u53d6\u4ed6&#xff0c;\u5c06\u5176\u653e\u5165\u56fe\u4e2d&#xff0c;\u7136\u540e\u8bb0\u5f55\u8fb9\u957f<\/p>\n<p>16 \u5faa\u73af\u4ee5\u4e0a\u6b65\u9aa414\u4e0e\u6b65\u9aa415\u3002<\/p>\n<p>17 \u5f53\u65e0\u8fb9\u53ef\u9009\u65f6&#xff0c;\u7a0b\u5e8f\u7ec8\u6b62<\/p>\n<p>\u6d41\u7a0b\u5df2\u7136\u5927\u81f4\u68b3\u7406\u4e86\u4e00\u904d&#xff0c;\u4e0b\u9762&#xff0c;\u5c31\u662f\u7a0b\u5e8f\u7684\u6784\u5efa\u4e86\u3002<\/p>\n<\/p>\n<p>\u5e76\u67e5\u96c6&#xff08;Disjoint-Set&#xff09;<\/p>\n<p>\u6bd4\u8f83\u62b1\u6b49\u7684\u662f&#xff0c;\u6211\u5e76\u6ca1\u6709\u5728\u524d\u51e0\u5929\u7684\u6bcf\u65e5\u4e00\u7ec3\u4e2d\u53d1\u5e03\u6709\u5173\u5e76\u67e5\u96c6\u7684\u5185\u5bb9&#xff0c;\u6240\u4ee5&#xff0c;\u5728\u6b64\u5904\u5361\u4f4f\u7684\u5c0f\u4f19\u4f34\u4eec\u53ef\u4ee5\u5148\u53bbB\u7ad9\u67e5\u8be2\u76f8\u5173\u5185\u5bb9&#xff0c;\u51e0\u5206\u949f\u5c31\u53ef\u4ee5\u641e\u5b9a\u3002<\/p>\n<p>\u7b80\u5355\u6765\u8bf4&#xff0c;\u5e76\u67e5\u96c6\u5c31\u662f\u67e5\u8be2\u6bcf\u4e00\u4e2a\u8282\u70b9\u5f52\u5c5e\u7684\u4e00\u79cd\u6811\u72b6\u7ed3\u6784\u3002<\/p>\n<p>\u5b66\u4e60\u4e86\u5e76\u67e5\u96c6\u540e&#xff0c;\u6211\u4eec\u6765\u6784\u5efa\u4e00\u4e2a\u5e76\u67e5\u96c6&#xff0c;\u6765\u5e2e\u52a9\u6211\u4eec\u5224\u65ad\u6240\u9009\u8282\u70b9\u662f\u5426\u6210\u73af\u3002<\/p>\n<p>1 \u5e76\u67e5\u96c6\u6709\u56db\u4e2a\u8981\u7d20&#xff1a;\u8282\u70b9\u4e2a\u6570\u3001\u6bcf\u4e2a\u8282\u70b9\u7684\u79e9&#xff08;\u6811\u7684\u9ad8\u5ea6&#xff09;\u3001\u7236\u8282\u70b9\u3001\u5b50\u8282\u70b9<\/p>\n<p>2 \u4e3a\u4e86\u66f4\u5feb\u4e00\u4e9b&#xff0c;\u4e5f\u8bb8\u6211\u4eec\u7684\u5143\u7d20\u5e76\u4e0d\u662f\u53ea\u67e5\u8be2\u8fd9\u4e48\u4e00\u6b21&#xff0c;\u6211\u4eec\u5e0c\u671b\u540e\u7eed\u7684\u67e5\u8be2\u4e2d\u80fd\u5feb\u4e00\u4e9b\u3002\u60f3\u60f3\u770b\u5427&#xff0c;\u8fd9\u4e2a\u7ed3\u6784\u6811\u662f\u600e\u4e48\u6784\u6210\u7684&#xff1f;\u6bd4\u8f83\u574f\u7684\u60c5\u51b5\u662f\u4e00\u7ea7\u4e00\u7ea7\u5411\u4e0a\u67e5\u8be2&#xff0c;\u90a3\u6211\u5e0c\u671b\u5728\u8fd9\u6b21\u4e00\u67e5\u8be2\u540e&#xff0c;\u4ee5\u540e\u5c31\u4e0d\u8981\u8fd9\u6837\u8fd9\u4e48\u6162\u7684\u67e5\u8be2\u4e86&#xff0c;\u6240\u4ee5\u6211\u76f4\u63a5\u628a\u8fd9\u4e00\u7ea7\u8282\u70b9\u6302\u5230\u7236\u8282\u70b9\u4e0a\u9762&#xff0c;\u8fd9\u6837&#xff0c;\u6211\u5728\u4e0b\u6b21\u67e5\u8be2\u540e&#xff0c;\u53ea\u9700\u8981\u518d\u5411\u4e0a\u67e5\u4e00\u7ea7&#xff0c;\u6211\u5c31\u77e5\u9053\u672c\u8282\u70b9\u662f\u4ece\u5c5e\u4e8e\u8fd9\u4e2a\u7236\u8282\u70b9\u3002\u4eba\u4eec\u7ed9\u8fd9\u79cd\u64cd\u4f5c\u53d6\u4e86\u4e00\u4e2a\u52a8\u4eba\u7684\u540d\u5b57&#xff0c;\u8def\u5f84\u538b\u7f29\u3002<\/p>\n<p>3 \u4e0a\u9762\u8bf4\u7684\u662f\u5df2\u7ecf\u8fde\u63a5\u597d\u7684\u60c5\u51b5&#xff0c;\u5982\u679c&#xff0c;\u662f\u65b0\u8fde\u63a5\u7684\u5462&#xff1f;\u8fd9\u5c31\u610f\u5473\u7740&#xff0c;\u5408\u5e76\u3002\u5408\u5e76\u4e5f\u662f\u6709\u8bb2\u7a76\u7684&#xff0c;\u54ea\u4e24\u4e2a\u8282\u70b9\u5408\u5e76&#xff1f;\u4ee5\u4ec0\u4e48\u5f62\u5f0f\u5408\u5e76&#xff1f;<\/p>\n<p>4 \u7b2c\u4e00&#xff0c;\u5408\u5e76\u901a\u5e38\u662f\u7236\u8282\u70b9\u4e4b\u95f4\u8fdb\u884c\u5408\u5e76&#xff0c;\u5982\u679c\u4f60\u60f3\u628a\u4e00\u4e2a\u8282\u70b9\u5408\u5e76\u5230\u53e6\u4e00\u4e2a\u8282\u70b9\u4e0a&#xff0c;\u8bf7\u52a1\u5fc5\u627e\u5230\u8fd9\u4e24\u4e2a\u8282\u70b9\u7684\u7236\u8282\u70b9&#xff0c;\u7136\u540e\u518d\u5408\u5e76\u7236\u8282\u70b9<\/p>\n<p>5 \u7b2c\u4e8c&#xff0c;\u5c31\u5408\u5e76\u7684\u65b9\u5f0f\u800c\u8a00&#xff0c; \u901a\u5e38\u6709\u4e24\u79cd&#xff0c;\u4e0d\u8fc7\u4ed6\u4eec\u7edf\u79f0\u4e3a\u201c\u6309\u79e9\u5408\u5e76\u201d&#xff0c;\u7b2c\u4e00\u79cd\u662f\u6309\u6811\u9ad8\u5408\u5e76&#xff0c;\u4e5f\u5c31\u662f\u54ea\u68f5\u6811\u66f4\u9ad8&#xff0c;\u77ee\u7684\u90a3\u68f5\u6811\u7684\u7236\u8282\u70b9\u5c31\u8fde\u63a5\u5230\u9ad8\u7684\u90a3\u9897\u6811\u7684\u7236\u8282\u70b9\u4e0a\u3002\u4e0d\u8fc7\u8fd9\u4f1a\u4ea7\u751f\u4e00\u4e9b\u5e7b\u89c9\u3002\u56e0\u4e3a\u6d89\u53ca\u5230\u8def\u5f84\u538b\u7f29\u7684\u8bdd&#xff0c;\u8fdb\u884c\u8def\u5f84\u538b\u7f29\u540e&#xff0c;\u6811\u7684\u5b9e\u9645\u9ad8\u5ea6\u53ef\u80fd\u4f1a\u53d8\u77ee&#xff0c;\u5bfc\u81f4\u4f1a\u51fa\u73b0\u4e24\u68f5\u6811\u7b49\u9ad8&#xff0c;\u6216\u8005\u9ad8\u4e00\u4e9b\u7684\u6811\u5408\u5e76\u5230\u77ee\u4e00\u4e9b\u7684\u6811\u4e0a\u9762&#xff0c;\u4e0d\u8fc7\u65e0\u4f24\u5927\u96c5&#xff0c;\u8fd9\u4e2a\u6cd5\u5b50\u8fd8\u662f\u5f88\u597d\u7528\u7684&#xff0c;\u5e76\u4e0d\u4f1a\u56e0\u4e3a\u4e9b\u8bb8\u5e7b\u89c9\u4ea7\u751f\u4e0d\u7a33\u5b9a\u6027\u3002<\/p>\n<p>6 \u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u5e7b\u89c9&#xff0c;\u6211\u4eec\u6709\u7b2c\u4e8c\u79cd\u529e\u6cd5&#xff0c;\u6309\u8282\u70b9\u4e2a\u6570\u5408\u5e76&#xff0c;\u8c01\u8282\u70b9\u66f4\u591a&#xff0c;\u8c01\u5c31\u505a\u7238\u7238&#xff0c;\u56e0\u4e3a\u513f\u5b50\u7684\u4e2a\u6570\u4e0d\u4f1a\u56e0\u8def\u5f84\u538b\u7f29\u800c\u53d1\u751f\u6539\u53d8\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4ee3\u7801\u5b9e\u73b0&#xff1a;<\/p>\n<p>class DisjointSetUnion {<br \/>\nprivate:<br \/>\n    vector&lt;int&gt; f, rank;<br \/>\n    int n;<\/p>\n<p>public:<br \/>\n    DisjointSetUnion(int _n) {<br \/>\n        n &#061; _n;<br \/>\n        rank.resize(n, 1);<br \/>\n        f.resize(n);<br \/>\n        for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n            f[i] &#061; i;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    int find(int j) {<br \/>\n        return f[j] &#061;&#061; j ? j : f[j] &#061; find(f[j]);<br \/>\n    }<\/p>\n<p>    int unionSet(int j, int k) {<br \/>\n        int fj &#061; find(j), fk &#061; find(k);<br \/>\n        if (fj &#061;&#061; fk) {<br \/>\n            return false;<br \/>\n        }<br \/>\n        if (rank[fj] &lt; rank[fk]) {<br \/>\n            swap(fj, fk);<br \/>\n        }<br \/>\n        rank[fj] &#043;&#061; rank[fk];<br \/>\n        f[fj] &#061; fj;<br \/>\n        return true;<br \/>\n    }<br \/>\n}; <\/p>\n<p>\u5176\u4e2d&#xff0c;<\/p>\n<p>find&#xff08;&#xff09;\u51fd\u6570\u5c31\u662f\u8def\u5f84\u538b\u7f29&#xff0c;\u4ee5\u8fed\u4ee3\u7684\u65b9\u5f0f\u5b8c\u6210\u3002<\/p>\n<p>unionSet&#xff08;&#xff09;\u51fd\u6570\u5c31\u662f\u68c0\u67e5\u662f\u5426\u6210\u73af&#xff0c;\u4ee5\u53ca\u6309\u79e9\u5408\u5e76\u3002<\/p>\n<\/p>\n<p>\u63a5\u7740&#xff0c;\u6211\u4eec\u6765\u6784\u5efa\u4e8c\u53c9\u7d22\u5f15\u6811&#xff08;Binary Indexed Tree&#xff09;\u7684\u7c7b&#xff0c;\u53c8\u540d\u6811\u72b6\u6570\u7ec4&#xff0c;\u6ca1\u5b66\u8fc7\u7684\u5c0f\u4f19\u4f34\u53ef\u4ee5\u770b\u770b\u8fd9\u4e2a\u89c6\u9891<span class=\"link-card-box\"><span class=\"link-title\">https:\/\/www.bilibili.com\/video\/BV1pE41197Qj\/?spm_id_from&#061;333.1387.homepage.video_card.click&amp;vd_source&#061;f8b81fa5a70ab21de75192e5c7ec720c<\/span><span class=\"link-link\"><img decoding=\"async\" class=\"link-link-icon\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250815180033-689f75c1e06e1.png\" \/>https:\/\/www.bilibili.com\/video\/BV1pE41197Qj\/?spm_id_from&#061;333.1387.homepage.video_card.click&amp;vd_source&#061;f8b81fa5a70ab21de75192e5c7ec720c<\/span><\/span><\/p>\n<p>\u597d\u5427&#xff0c;\u6211\u627f\u8ba4\u6709\u4e9b\u64cd\u4e4b\u8fc7\u6025\u3002\u6784\u5efa\u4ed6\u7684\u539f\u56e0\u662f&#xff1a;\u5feb\u901f\u627e\u5230\u5206\u9694\u7684\u56db\u5757P1&#xff0c;2&#xff0c;3&#xff0c;4\u4e2d&#xff0c;\u6bcf\u4e2a\u533a\u57df\u7684\u6700\u5c0f\u8fb9<\/p>\n<p>1 \u9996\u5148&#xff0c;\u6784\u6210\u6811\u72b6\u6570\u7ec4\u7684\u8981\u7d20\u6709\u4e09\u4e2a&#xff1a;<\/p>\n<p>\u2460\u7528\u4e8e\u8bb0\u5f55\u6570\u503c\u7684\u6570\u7ec4&#xff1a;\u8fd9\u91cc\u662f\u8bb0\u5f55\u6bcf\u4e2a\u8282\u70b9\u672c\u8eab\u7684\u7279\u5f81\u503c&#xff0c;\u8fd9\u91cc\u7684\u7279\u5f81\u503c\u662f\u4e00\u4e2a\u7edf\u79f0\u3002\u5148\u7ed9\u8fd9\u4e2a\u6570\u7ec4\u547d\u4e2a\u540d\u5427&#xff0c;\u65e2\u7136\u4ed6\u53eb\u6811\u72b6\u6570\u7ec4&#xff0c;\u90a3\u6211\u4eec\u5c31\u7ba1\u4ed6\u53ebtree\u3002\u5bf9\u4e8etree\u800c\u8a00&#xff0c;\u5b9e\u9645\u4e0a&#xff0c;\u5b83\u8bb0\u5f55\u4e86\u4e24\u79cd\u4fe1\u606f\u3002\u770b\u770b\u4ed6\u7684\u5f62\u6001tree[pos]&#061;val<\/p>\n<p>\u6211\u4eec\u53d1\u73b0&#xff0c;\u5b83\u53ef\u4ee5\u5728\u4e24\u4e2a\u5730\u65b9\u8bb0\u5f55\u4fe1\u606f&#xff1a;\u6570\u7ec4\u7d22\u5f15pos&#xff0c;\u5b58\u50a8\u7684\u503cval\u3002<\/p>\n<p>\u8fd9\u5206\u522b\u7528\u4e8e\u5e72\u4ec0\u4e48\u5462&#xff1f;<\/p>\n<p>\u5bf9\u4e8e\u6570\u7ec4\u7d22\u5f15pos&#xff0c;\u7528\u6765\u5212\u5b9a\u533a\u57df&#xff0c;\u4e5f\u5c31\u662f\u6211\u4eec\u7684P1&#xff0c;2&#xff0c;3&#xff0c;4<\/p>\n<p>\u800c\u5b58\u50a8\u7684\u503cval&#xff0c;\u5219\u662f\u7528\u6765\u5224\u65ad\u6700\u77ed\u8fb9<\/p>\n<p>\u6211\u4eec\u4ecd\u65e7\u7528P1\u8fdb\u884c\u4e3e\u4f8b\u3002<\/p>\n<\/p>\n<p>\u6211\u4eec\u6765\u770b\u770bpos\u662f\u600e\u4e48\u6765\u7684&#xff0c;\u53c8\u662f\u600e\u4e48\u8fd0\u4f5c&#xff0c;\u624d\u62e5\u6709\u4e86\u5212\u5206\u533a\u57df\u7684\u80fd\u529b<\/p>\n<p>\u56de\u60f3\u4ee5\u4e0b\u5212\u5206\u533a\u57df\u7684\u6761\u4ef6&#xff1a;Xb-Xa&gt;0&#xff0c;\u4ee5\u53caYb-Xb&gt;C&#061;Ya-Xa<\/p>\n<p>\u9996\u5148&#xff0c;\u6211\u4eec\u9700\u8981\u786e\u4fdd\u53d6\u5230\u7684\u70b9&#xff0c;\u597d\u5427&#xff0c;\u5176\u5b9e\u6211\u4eec\u9700\u8981\u53d6\u4e24\u4e2a\u70b9\u3002\u5982\u4f55\u786e\u4fdd\u4f60\u5728\u4ee5\u5176\u4e2d\u4e00\u4e2a\u70b9\u4e3a\u57fa\u51c6\u70b9\u65f6&#xff0c;\u53e6\u4e00\u4e2a\u70b9\u4e00\u5b9a\u4f1a\u5728\u5176\u53f3\u4fa7&#xff0c;\u4e5f\u5c31\u662fXb-Xa&gt;0&#xff1f;\u5f88\u7b80\u5355&#xff0c;\u3010\u6392\u5e8f\u3011\u3002\u53ea\u8981\u6309\u7167X\u503c\u7684\u5927\u5c0f\u6392\u5e8f&#xff0c;\u6211\u4eec\u5148\u53d6X\u503c\u6700\u5c0f\u7684\u70b9\u4f5c\u4e3a\u57fa\u51c6\u70b9&#xff0c;\u90a3\u4e48\u5373\u4fbf\u53e6\u5916\u4e00\u4e2a\u70b9\u662f\u968f\u4fbf\u53d6\u7684&#xff0c;\u4f9d\u7136\u53ef\u4ee5Xb-Xa&gt;0\u3002<\/p>\n<p>\u5bf9\u4e8e\u6392\u5e8f&#xff0c;\u5b9e\u73b0\u65b9\u6cd5\u662f\u6784\u5efa\u4e00\u4e2a\u53ef\u4ee5\u540c\u65f6\u5b58\u50a8x&#xff0c;y\u503c\u7684\u5bf9\u8c61&#xff0c;\u4f60\u53ef\u80fd\u4f1a\u60f3\u5230\u6bcf\u65e5\u4e00\u7ec38\u7684\u952e\u503c\u5bf9&#xff0c;\u4f46\u8fd9\u91cc\u6211\u4eec\u4f7f\u7528\u7ed3\u6784\u4f53\u66f4\u5408\u9002\u4e00\u4e9b&#xff0c;\u56e0\u4e3a\u6211\u4eec\u8fd8\u6709\u522b\u7684\u4fe1\u606f\u9700\u8981\u5b58\u50a8&#xff0c;\u6bd4\u5982\u2014\u2014\u7d22\u5f15\u3002\u6240\u4ee5\u952e\u503c\u5bf9\u662f\u4e0d\u5408\u9002\u7684\u3002<\/p>\n<p>struct Pos {<br \/>\n    int id, x, y;<br \/>\n}&#xff1b; <\/p>\n<p>\u6211\u4eec\u6709\u8bf8\u591a\u8282\u70b9&#xff0c;\u663e\u7136\u4e00\u4e2a\u7ed3\u6784\u4f53\u662f\u4e0d\u591f\u7684&#xff0c;\u6240\u4ee5\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u5b58\u653e\u7ed3\u6784\u4f53\u7684\u5bb9\u5668\u3002<\/p>\n<p>vector&lt;Pos&gt; pos <\/p>\n<p>\u6709\u4e86\u8fd9\u4e2a&#xff0c;\u6211\u4eec\u5c31\u53ef\u4ee5\u8fdb\u884c\u6392\u5e8f\u7684\u64cd\u4f5c\u4e86<\/p>\n<p>\u6211\u4eec\u77e5\u9053&#xff0c;C&#043;&#043;\u7684std::sort\u51fd\u6570\u9ed8\u8ba4\u4f7f\u7528\u201c&lt;&#034;\u8fd0\u7b97\u7b26\u6765\u6bd4\u8f83\u4e24\u4e2a\u5143\u7d20\u7684\u5927\u5c0f&#xff0c;\u5bf9\u4e8e\u81ea\u5b9a\u4e49\u7ed3\u6784\u4f53Pos\u800c\u8a00&#xff0c;\u5f53\u6211\u4eec\u91cd\u8f7d\u4e86\u8fd0\u7b97\u7b26&#034;&lt;&#034;\u540e&#xff0c;sort\u5c31\u4f1a\u8c03\u7528\u8fd9\u4e2a\u91cd\u8f7d\u7248\u672c\u6765\u51b3\u5b9a\u5143\u7d20\u7684\u6392\u5217\u987a\u5e8f\u3002<\/p>\n<p>\u5bf9\u4e8ePos\u800c\u8a00&#xff0c;\u6211\u4eec\u5173\u6ce8\u7684\u662f\u4ed6\u7684X\u503c&#xff0c;\u56e0\u4e3a\u6211\u4eec\u8981\u4fdd\u8bc1\u6240\u9009\u8282\u70b9\u5728\u57fa\u51c6\u8282\u70b9\u53f3\u4fa7\u3002\u4f46\u60c5\u51b5\u5b9e\u9645\u4e0a\u8fd8\u6709\u53e6\u4e00\u79cd\u60c5\u51b5&#xff0c;\u4e5f\u662f\u552f\u4e00\u7684\u4e00\u79cd\u60c5\u51b5&#xff1a;\u6240\u9009\u4e24\u70b9X\u503c\u76f8\u540c\u3002\u8fd9\u663e\u7136\u4e5f\u9700\u8981\u4e00\u79cd\u6392\u5e8f\u65b9\u5f0f&#xff0c;\u56e0\u4e3a\u4ed6\u662f\u771f\u5b9e\u5b58\u5728\u7684\u60c5\u51b5&#xff0c;\u6211\u4eec\u65e0\u6cd5\u5ffd\u7565\u4ed6\u3002\u6240\u4ee5&#xff0c;\u6211\u4eec\u4e5f\u8981\u4e3a\u4ed6\u6765\u6d89\u53ca\u4e00\u4e2a\u6bd4\u8f83\u65b9\u5f0f&#xff0c;\u7b80\u5355\u8d77\u89c1&#xff0c;\u4ecd\u65e7\u6bd4\u8f83Ya&lt;Yb\u5373\u53ef\u3002\u6211\u4eec\u5728\u7ed3\u6784\u4f53\u4e2d\u8865\u5145\u4e00\u6761\u8fd0\u7b97\u7b26\u91cd\u8f7d\u51fd\u6570&#xff0c;\u4ee5\u4fbfsort\u51fd\u6570\u53ef\u4ee5\u8c03\u7528\u4ed6\u3002<\/p>\n<p>struct Pos {<br \/>\n    int id, x, y;<br \/>\n    bool operator&lt;(const Pos&amp; a) const { return x &#061;&#061; a.x ? y &lt; a.y : x &lt; a.x; }<br \/>\n}; <\/p>\n<p>\u8fd9\u91cc\u9700\u8981\u6ce8\u610f\u7684\u662f&#xff0c;\u4e09\u76ee\u8fd0\u7b97\u7b26\u201c\u00a0 &#xff1f;&#xff1a;\u201d\u5f62\u6210\u7684\u662f\u4e00\u4e2a\u6574\u4f53&#xff0c;\u5e76\u4e0d\u662f\u76f4\u63a5return x&#xff1b;\u800c\u662f\u901a\u8fc7\u5927\u5c0f\u7684\u6bd4\u8f83\u8fd4\u56de\u4e00\u4e2abool\u503c\u3002<\/p>\n<p>\u7136\u540e\u8fdb\u884c\u6392\u5e8f<\/p>\n<p>sort(pos.begin(), pos.end()); <\/p>\n<p>\u73b0\u5728&#xff0c;\u6570\u7ec4pos\u4ee5X\u503c\u4ece\u5c0f\u5230\u5927\u7684\u5f62\u5f0f\u6392\u5217\u597d\u4e86\u3002<\/p>\n<\/p>\n<p>\u5b8c\u6210\u4e86\u7b2c\u4e00\u4e2a\u6761\u4ef6\u7684\u5224\u5b9a\u540e&#xff0c;\u5c31\u9700\u8981\u8fdb\u884c\u7b2c\u4e8c\u4e2a\u6761\u4ef6\u7684\u5224\u65ad&#xff0c;\u6d89\u53ca\u5230\u8282\u70b9\u7684\u7279\u5f81\u503cYb-Xb<\/p>\n<p>\u5bf9\u4e8e\u8fd9\u6837\u7684\u8ba1\u7b97&#xff0c;\u6211\u4eec\u53ef\u4ee5\u590d\u7528\u7ed3\u6784\u4f53Pos&#xff0c;\u8ba1\u7b97\u6bcf\u4e00\u4e2a\u8282\u70b9\u7684\u7279\u5f81\u503c&#xff0c;\u5bf9\u6b64&#xff0c;\u6211\u4eec\u540c\u6837\u9700\u8981\u4e00\u4e2a\u5bb9\u5668\u6765\u5b58\u50a8\u8fd9\u4e9b\u8ba1\u7b97\u7684\u503c\u3002\u7531\u4e8e\u8fd9\u662f\u4e00\u4e2a\u6574\u6570\u5b9a\u503c&#xff0c;\u6211\u4eec\u628a\u7c7b\u578b\u8bbe\u4e3aint<\/p>\n<p>  vector&lt;int&gt; a(n); <\/p>\n<p>\u7136\u540e\u904d\u5386vector&lt;Pos&gt; pos\u4e2d\u7684\u6240\u6709\u5143\u7d20&#xff0c;\u5c06\u8ba1\u7b97\u503c\u8bb0\u5f55\u5230vector&lt;int&gt; a(n)\u4e2d<\/p>\n<p>for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n  a[i] &#061; pos[i].y &#8211; pos[i].x;<br \/>\n} <\/p>\n<p>\u6709\u65f6\u4f1a\u51fa\u73b0\u4e00\u4e9b\u8282\u70b9Y-X\u76f8\u540c\u7684\u60c5\u51b5&#xff0c;\u8fd9\u610f\u5473\u7740\u8fd9\u4e9b\u8282\u70b9\u90fd\u5904\u4e8e\u57fa\u51c6\u8282\u70b9\u7684\u540c\u4e00\u4e2a\u533a\u57df\u5185&#xff0c;\u6bd4\u5982\u90fd\u5904\u4e8e\u57fa\u51c6\u5143\u7d20\u7684P1\u533a\u57df\u5185\u3002<\/p>\n<p>\u8fd9\u4e2a\u73b0\u8c61\u9664\u4e86\u544a\u8bc9\u6211\u4eec\u4ed6\u4eec\u5904\u4e8e\u540c\u4e00\u4e2a\u533a\u57df&#xff0c;\u8fd8\u544a\u8bc9\u6211\u4eec\u4ed6\u4f1a\u8ba9\u7a0b\u5e8f\u68c0\u7d22\u65f6\u95f4\u53d8\u957f&#xff0c;\u8fd9\u662f\u6211\u4eec\u4e0d\u613f\u770b\u5230\u7684&#xff0c;\u6bd4\u8f83\u597d\u7684\u529e\u6cd5\u662f\u8ba9\u6bcf\u4e00\u4e2a\u7279\u5f81\u503cY-X\u53d8\u5f97\u72ec\u7279&#xff0c;\u6210\u4e3a\u7d22\u5f15\u4e00\u6837\u7684\u5b58\u5728&#xff0c;\u4f46\u6211\u4eec\u53c8\u4e0d\u5e0c\u671b\u6539\u53d8\u6570\u7ec4a&#xff0c;\u56e0\u4e3a\u6570\u7ec4a\u7684\u7d22\u5f15\u4ee3\u8868\u4ed6\u662f\u4e0d\u540c\u8282\u70b9\u4ea7\u751f\u7684\u7279\u5f81\u503c\u3002<\/p>\n<p>\u6240\u4ee5\u6211\u4eec\u53e6\u8bbe\u4e00\u4e2a\u6570\u7ec4b&#xff0c;\u4e13\u95e8\u7528\u4e8e\u5b58\u653e\u6ca1\u6709\u91cd\u590d\u7684\u7279\u5f81\u503cY-X&#xff0c;\u8ba9\u5176\u6210\u4e3a\u5206\u754c\u7ebf\u4e00\u6837\u7684\u5b58\u5728&#xff0c;\u901a\u8fc7\u68c0\u7d22b\u7684\u7d22\u5f15&#xff0c;\u6211\u4eec\u5c31\u80fd\u77e5\u9053\u5750\u6807\u5904\u4e8e\u54ea\u4e00\u4e2a\u533a\u57df\u3002\u7531\u4e8e\u6211\u4eec\u4e0d\u77e5\u9053\u91cd\u590d\u503c\u7684\u4e2a\u6570&#xff0c;\u5148\u6682\u4e14\u8bbe\u5bb9\u5668\u5927\u5c0f\u4e3an<\/p>\n<p>vector&lt;int&gt; b(n)&#xff1b; <\/p>\n<p>\u5f53\u7136&#xff0c;\u5408\u7406\u8d77\u89c1&#xff0c;\u6211\u4eec\u5e94\u8be5\u4e0ea\u4e00\u540c\u5904\u7406&#xff0c;\u4e5f\u5c31\u662f\u5728\u4e0a\u4e00\u6761\u7a0b\u5e8f\u7684for\u5faa\u73af\u52a0\u4e0a\u6570\u7ec4b\u7684\u5904\u7406<\/p>\n<p>for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n            a[i] &#061; pos[i].y &#8211; pos[i].x;<br \/>\n            b[i] &#061; pos[i].y &#8211; pos[i].x;<br \/>\n        } <\/p>\n<p>\u7136\u540e&#xff0c;\u5bf9\u6570\u7ec4b\u8fdb\u884c\u4e0a\u8ff0\u64cd\u4f5c&#xff0c;\u8ba9\u6bcf\u4e2a\u7279\u5f81\u503c\u72ec\u7acb&#xff0c;\u5e76\u4f7f\u4e4b\u53ef\u4ee5\u6210\u4e3a\u88ab\u5408\u7406\u68c0\u7d22\u7684\u5b58\u5728\u3002<\/p>\n<p>\u4e3a\u4e86\u53ef\u4ee5\u8f7b\u6613\u68c0\u7d22\u4ed6&#xff0c;\u6211\u4eec\u5148\u628a\u6570\u7ec4b\u8fdb\u884c\u6392\u5e8f&#xff0c;\u8fd9\u6837&#xff0c;\u6211\u4eec\u5c31\u53ef\u4ee5\u901a\u8fc7\u4e0b\u6807\u7684\u5f62\u5f0f\u8fdb\u884c\u533a\u57df\u5212\u5206\u3002\u540c\u65f6&#xff0c;\u8fd9\u4e5f\u662f\u4e3a\u4e86\u9002\u914d\u53bb\u91cd\u65f6erase\u51fd\u6570\u7684\u4f7f\u7528&#xff0c;\u56e0\u4e3aerase\u51fd\u6570\u53ea\u80fd\u5220\u53bb\u7279\u5b9a\u533a\u57df\u7684\u6570\u5b57\u3002<\/p>\n<p>    sort(b.begin(), b.end()); <\/p>\n<p>\u7136\u540e\u8fdb\u884c\u53bb\u91cd\u3002<\/p>\n<p> b.erase(unique(b.begin(), b.end()), b.end()); <\/p>\n<p>\u9996\u5148\u662f\u5229\u7528unique\u51fd\u6570\u628a\u6570\u7ec4b\u6240\u6709\u91cd\u590d\u7684\u5143\u7d20\u79fb\u5230\u961f\u5217\u672b\u5c3e&#xff0c;\u7136\u540e\u8fd4\u56de\u4e00\u4e2a\u6307\u5411\u7b2c\u4e00\u4e2a\u91cd\u590d\u5143\u7d20\u7684\u8fed\u4ee3\u5668\u3002\u4e4b\u540e&#xff0c;erase\u51fd\u6570\u5927\u624b\u53d1\u529b&#xff0c;\u62b9\u9664\u4e24\u4e2a\u8fed\u4ee3\u5668\u4e4b\u95f4\u7684\u91cd\u590d\u5143\u7d20\u3002\u73b0\u5728&#xff0c;\u6570\u7ec4b\u6709\u4e86\u4e00\u4e2a\u597d\u542c\u7684\u540d\u5b57\u2014\u2014\u3010\u6620\u5c04\u8868\u3011\u3002\u5f53\u7136&#xff0c;\u4f60\u559c\u6b22\u7ba1\u4ed6\u53eb&#xff0c;\u3010\u5b57\u5178\u3011&#xff0c;\u4e5f\u662f\u53ef\u4ee5\u88ab\u63a5\u53d7\u7684\u3002<\/p>\n<p>\u8bf4\u4e86\u8fd9\u4e48\u591a&#xff0c;\u4e0d\u8981\u5fd8\u8bb0\u521d\u5fc3&#xff0c;\u6211\u4eec\u662f\u8981\u89e3\u91capos\u8fd9\u4e2a\u6570\u7ec4tree\u7684\u7d22\u5f15\u662f\u600e\u4e48\u6765\u7684<\/p>\n<p>\u4e3a\u4e86\u628a\u7d22\u5f15\u540d\u79f0\u548c\u6570\u7ec4\u540dpos\u533a\u5206&#xff0c;\u6211\u4eec\u628a\u8ba1\u7b97\u7528\u7684\u7d22\u5f15\u540d\u79f0\u53ebposs<\/p>\n<p>int poss &#061; lower_bound(b.begin(), b.end(), a[i]) &#8211; b.begin() &#043; 1; <\/p>\n<p>\u901a\u8fc7lower_bound\u51fd\u6570&#xff0c;\u4ed6\u4f1a\u8fd4\u56de\u4e00\u4e2a\u5728\u6570\u7ec4b\u4e2d\u4e0e\u6570\u7ec4a\u6570\u503c\u76f8\u7b49\u65f6\u7684\u8fed\u4ee3\u5668&#xff0c;\u5f53\u7136&#xff0c;\u6211\u4eec\u9700\u8981\u628a\u4ed6\u5904\u7406\u4e3a\u6570\u7ec4\u7d22\u5f15&#xff0c;\u8fed\u4ee3\u5668\u5f53\u7136\u4e0d\u80fd\u6210\u4e3a\u7d22\u5f15\u3002\u4f46\u6570\u7ec4b\u662f\u4e00\u4e2avector\u6570\u7ec4&#xff0c;\u4ed6\u7684\u5185\u5bb9\u662f\u8fde\u7eed\u5b58\u50a8\u7684&#xff0c;\u90a3\u4e48\u8fed\u4ee3\u5668\u4e4b\u95f4\u76f8\u51cf&#xff0c;\u5f97\u5230\u4e00\u4e2a\u5dee\u503c&#xff0c;\u8fd9\u5c31\u662f\u6570\u7ec4b\u6b64\u65f6\u7684\u7d22\u5f15\u4e86\u3002\u4f46\u8fd9\u8fd8\u4e0d\u591f&#xff0c;\u56e0\u4e3a\u4e8c\u53c9\u7d22\u5f15\u6811\u7684\u6807\u53f7\u662f\u4ece\u30101\u3011\u5f00\u59cb\u7684&#xff0c;\u800c\u6570\u7ec4b\u662f\u4ece\u30100\u3011\u5f00\u59cb\u7684&#xff0c;\u4e0d\u8fdb\u884c\u6807\u53f7\u5bf9\u9f50\u7684\u8bdd&#xff0c;\u4f1a\u51fa\u73b0<\/p>\n<p>lowbit&#xff08;0&#xff09;\u65e0\u610f\u4e49\u7684\u95ee\u9898&#xff0c;\u6240\u4ee5&#xff0c;\u6211\u4eec\u9700\u8981\u4e3a\u6570\u7ec4b\u7684\u7d22\u5f15<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0lower_bound(b.begin(), b.end(), a[i]) &#8211; b.begin()\u00a0<\/p>\n<p>\u8fdb\u884c\u52a01\u7684\u5904\u7406&#xff0c;\u4ee5\u4fbf\u5bf9\u9f50\u4e8c\u53c9\u7d22\u5f15\u6811\u7684\u6807\u53f7\u3002<\/p>\n<p>\u8fd9\u5c31\u662fpos\u7684\u6765\u6e90\u4e86&#xff0c;\u5982\u4f55\u4f7f\u7528\u5b83&#xff0c;\u6211\u4eec\u540e\u9762\u4f1a\u7ee7\u7eed\u8bb2\u89e3<\/p>\n<\/p>\n<p>\u63a5\u4e0b\u6765\u8bb2\u89e3\u7684\u662f\u6570\u7ec4tree\u4e2d\u5b58\u50a8\u7684val&#xff0c;\u8fd9\u53c8\u662f\u600e\u4e48\u6765\u7684<\/p>\n<p>\u6587\u7ae0\u6709\u4e9b\u592a\u957f\u4e86&#xff0c;\u6211\u4eec\u91cd\u6e29\u4e00\u4e0b\u4e0a\u9762\u7684\u5185\u5bb9<\/p>\n<p>\u5728\u5b8c\u6210\u533a\u57df\u7684\u5224\u522b\u4e4b\u540e&#xff0c;\u6211\u4eec\u5c31\u9700\u8981\u8fdb\u884c\u6700\u77ed\u8fb9\u7684\u5224\u65ad\u3002\u6211\u4eec\u77e5\u9053&#xff0c;\u5bf9\u4e8e\u5904\u4e8eP1\u533a\u57df\u7684\u70b9\u800c\u8a00&#xff0c;\u66fc\u54c8\u987f\u8ddd\u79bb\u53ef\u4ee5\u88ab\u8868\u793a\u4e3aD&#061;&#xff08;Xz-Xa&#xff09;&#043;&#xff08;Yz-Ya&#xff09;&#061;&#xff08;Xz&#043;Yz&#xff09;-&#xff08;Xa&#043;Ya&#xff09;&#xff0c;\u6709\u610f\u601d\u7684\u662f&#xff0c;Xa&#043;Ya\u5728\u6b64\u5904\u5b9e\u9645\u4e0a\u662f\u4e2a\u5b9a\u503c&#xff0c;\u5728\u5904\u7406\u7684\u8fc7\u7a0b\u4e2d&#xff0c;\u4f1a\u6539\u53d8\u7684\u53ea\u6709Xz&#043;Yz\u3002\u4e5f\u5c31\u662f\u8bf4&#xff1a;&#xff08;Xz&#043;Yz&#xff09;\u8d8a\u5927&#xff0c;\u66fc\u54c8\u987f\u8ddd\u79bb\u5c31\u8d8a\u5927<\/p>\n<p>pos\u8fd9\u4e2a\u7d22\u5f15&#xff0c;\u4e8b\u5b9e\u4e0a\u5c31\u5b8c\u6210\u4e86\u533a\u5757\u7684\u5212\u5206&#xff0c;\u6240\u4ee5&#xff0c;tree\u5b58\u50a8\u7684\u503c\u5e94\u8be5\u662f\u5904\u4e8eP1\u533a\u5757\u7684\u8282\u70b9\u7684\u66fc\u54c8\u987f\u8ddd\u79bb\u7684\u9b54\u6539\u503c&#xff08;Xz&#043;Yz&#xff09;&#xff0c;\u5bf9\u4e8e\u8fd9\u4e2a\u503c\u7684\u4f7f\u7528&#xff0c;\u6211\u4eec\u540e\u9762\u4f1a\u8fdb\u884c\u8bb2\u89e3<\/p>\n<p>\u2461\u7528\u4e8e\u8bb0\u5f55\u7d22\u5f15\u7684\u6570\u7ec4&#xff1a;\u901a\u8fc7\u76f8\u540c\u7684\u7f16\u53f7\u6765\u8bb0\u5f55\u7d22\u5f15\u3002\u4e8b\u5b9e\u4e0a&#xff0c;\u8fd9\u4e2a\u6570\u7ec4\u6709\u4e24\u4e2a\u7d22\u5f15&#xff0c;\u6211\u4eec\u9700\u8981\u5206\u6e05\u695a\u4e00\u4e9b\u3002\u6211\u4eec\u8bbe\u8fd9\u4e2a\u6570\u7ec4\u4e3aidRec\u3002\u5bf9\u4e8e\u8fd9\u4e2aidRec&#xff0c;\u8fdb\u884c\u67e5\u627e\u65f6&#xff0c;\u6709idRec[pos] &#061; id\u3002\u5176\u4e2dpos\u7684\u6765\u6e90&#xff0c;\u5728\u2460\u4e2d\u5df2\u7ecf\u89e3\u91ca\u8fc7\u3002\u73b0\u5728&#xff0c;\u6211\u4eec\u6765\u89e3\u91ca\u201cid\u201d\u5b58\u50a8\u4e86\u4ec0\u4e48\u503c\u3002<\/p>\n<p>id&#xff0c;\u5c31\u662f\u5f53\u524d\u6570\u7ec4tree\u6240\u4f7f\u7528\u7684poss\u7d22\u5f15&#xff0c;\u5728\u6570\u7ec4pos\u4e2d\u7684\u7f16\u53f7<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0pos[i]\u2014\u2014&gt;a[i]\u2014\u2014&gt;b[?]\u2014\u2014&gt;poss\u2014\u2014&gt;tree[poss]<\/p>\n<p>\u4e5f\u5c31\u662f\u8bf4&#xff0c;id&#061;i&#xff0c;\u4fdd\u7559\u8fd9\u4e2a\u4fe1\u606f&#xff0c;\u662f\u4e3a\u4e86\u4e4b\u540e\u5f97\u80dc\u6700\u5c0f\u8fb9\u65f6&#xff0c;\u8ba1\u7b97\u66fc\u54c8\u987f\u8ddd\u79bb\u7684\u4f9d\u636e<\/p>\n<p>\u2462\u6784\u9020BIT\u5b9e\u4f8b\u82b1\u8d39\u7684\u6570\u7ec4\u5927\u5c0f&#xff1a;\u6211\u4eec\u628a\u8fd9\u4e2a\u4f20\u5165\u7684\u4e1c\u897f\u53eb\u505an\u3002<\/p>\n<p>\u5bf9\u4e8en&#xff0c;\u5e94\u8be5\u4e0e\u6570\u7ec4tree\u542b\u6709\u7684\u5143\u7d20\u4e2a\u6570\u4e00\u81f4&#xff0c;\u8fd9\u6837&#xff0c;\u624d\u80fd\u7cbe\u786e\u6784\u5efa\u6570\u7ec4tree\u7684\u5927\u5c0f&#xff0c;\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u6d6a\u8d39&#xff0c;\u4e5f\u662f\u4e3a\u4e86\u9632\u6b62\u5b58\u50a8\u7a7a\u95f4\u4e0d\u8db3\u800c\u8d8a\u754c\u3002\u6240\u4ee5\u6709<\/p>\n<p>int num &#061; b.size(); <\/p>\n<p>\u8fd9\u91cc\u7684num\u4e0en\u4e0d\u662f\u4e00\u4e2a\u4e1c\u897f&#xff0c;\u7531\u4e8e\u6784\u5efa\u7684\u6570\u7ec4\u5f80\u5f80\u4ece0\u5f00\u59cb&#xff0c;\u6240\u4ee5\u5b9e\u9645\u4e0a\u6570\u7ec4tree\u548c\u6570\u7ec4idRec\u90fd\u8981\u6bd4\u5b9e\u9645\u5b58\u50a8\u5143\u7d20\u603b\u91cf\u5927\u4e00\u4f4d&#xff0c;\u4ee5\u7b26\u5408\u4e8c\u53c9\u7d22\u5f15\u6811\u7684\u5e94\u7528\u89c4\u5219&#xff0c;[0]\u53f7\u6570\u7ec4\u4e0d\u5b58\u50a8\u4e1c\u897f&#xff0c;\u53ea\u662f\u7528\u6765\u52a0\u585e\u3002\u4e5f\u5c31\u662f\u8bf4&#xff0c;n&#061;num&#043;1<\/p>\n<p>\u5bf9\u4e8enum\u800c\u8a00&#xff0c;\u8fd9\u4e2a\u503c\u8d8a\u5927&#xff0c;\u8bf4\u660eP1\u533a\u57df\u5212\u5206\u7684\u8d8a\u7cbe\u7ec6&#xff0c;\u4f46\u540c\u65f6\u4e5f\u610f\u5473\u7740\u641c\u7d22\u6548\u7387\u7684\u964d\u4f4e\u3002<\/p>\n<\/p>\n<p>\u62e5\u6709\u6240\u6709\u6784\u5efa\u4e8c\u53c9\u7d22\u5f15\u6811\u7684\u8981\u7d20\u4e4b\u540e&#xff0c;\u6211\u4eec\u5c31\u5f00\u59cb\u6784\u5efa\u4e8c\u53c9\u7d22\u5f15\u6811<\/p>\n<p>    BIT(int _n) {<br \/>\n        n &#061; _n;<br \/>\n        tree.resize(n, INT_MAX);<br \/>\n        idRec.resize(n, -1);<br \/>\n    } <\/p>\n<p>\u6211\u4eec\u5728\u521d\u59cb\u5316\u65f6&#xff0c;\u5e94\u8be5\u628a\u6570\u7ec4tree\u7684\u6bcf\u4e00\u4e2a\u5143\u7d20\u8bbe\u7f6e\u4e3a\u6700\u5927&#xff0c;\u7ed9\u4e88\u4e00\u4e2a\u521d\u59cb\u7684\u6bd4\u8f83\u503c&#xff0c;\u56e0\u4e3a\u6211\u4eec\u7684tree\u603b\u662f\u5b58\u50a8\u6700\u5c0f\u7684&#xff08;Xz&#043;Yz&#xff09;&#xff0c;\u6240\u4ee5\u521d\u59cb\u503c&#xff0c;\u6211\u4eec\u8981\u8bbe\u4e3a\u65e0\u7a77\u5927&#xff0c;\u867d\u7136\u65e0\u6cd5\u5728\u8ba1\u7b97\u673a\u5b9e\u73b0\u65e0\u7a77\u5927&#xff0c;\u4e0d\u8fc7\u6211\u4eec\u53ef\u4ee5\u7528int\u6574\u5f62\u53ef\u4ee5\u8868\u8fbe\u7684\u6700\u5927\u503c\u6765\u8868\u793a\u65e0\u7a77\u3002<\/p>\n<p>\u5bf9\u4e8e\u6570\u7ec4idRec\u800c\u8a00&#xff0c;\u4e3a\u4ec0\u4e48\u8981\u628a\u521d\u59cb\u5143\u7d20\u8bbe\u7f6e\u4e3a-1&#xff0c;\u8fd9\u5e76\u6ca1\u6709\u4ec0\u4e48\u7279\u6b8a\u7684&#xff0c;\u53ea\u662f\u56e0\u4e3a\u6b63\u6570\u548c\u96f6\u90fd\u9700\u8981\u88ab\u4f7f\u7528\u4e3a\u7f16\u53f7\u7d22\u5f15&#xff0c;\u6240\u4ee5\u6211\u4eec\u53ea\u80fd\u5728\u8d1f\u6570\u4e2d\u968f\u673a\u9009\u62e9\u4e00\u4e2a\u6570&#xff0c;\u8868\u793a\u6b64\u65f6\u5c1a\u672a\u5b58\u5728\u8be5\u533a\u57df\u7684tree\u88ab\u5173\u8054\u3002<\/p>\n<p>\u00a0\u6b64\u65f6\u4e8c\u53c9\u7d22\u5f15\u6811\u521d\u59cb\u5316\u5b8c\u6210&#xff0c;\u63a5\u4e0b\u6765&#xff0c;\u6211\u4eec\u6765\u5b9e\u73b0\u4e8c\u53c9\u7d22\u5f15\u6811\u7684\u529f\u80fd\u3002<\/p>\n<p>\u54c8\u54c8&#xff0c;\u9996\u5148&#xff0c;\u662f\u4e8c\u53c9\u7d22\u5f15\u6811\u6700\u5173\u952e\u7684\u641c\u67e5\u7ec4\u4ef6&#xff0c;lowbit&#xff08;&#xff09;<\/p>\n<p>    int lowbit(int k) { return k &amp; (-k); } <\/p>\n<p>\u4f4d\u4e0e\u8fd0\u7b97\u7b26&amp;\u9996\u5148\u4f1a\u628a\u5341\u8fdb\u5236\u7684k\u8f6c\u5316\u4e3a\u4e8c\u8fdb\u5236&#xff0c;\u7136\u540e-k\u53d8\u6210k\u53d6\u8865\u7801&#xff0c;\u4e5f\u5c31\u662fk\u6309\u4f4d\u53d6\u53cd&#xff0c;\u7136\u540e\u52a0\u4e00\u3002\u63a5\u7740&amp;\u8fd0\u7b97\u7b26\u5c31\u4f1a\u6bd4\u5bf9k\u4e0e-k\u4e4b\u95f4\u7684\u6570\u5b57&#xff0c;\u82e5\u540c\u4e00\u4f4d\u6b21\u90fd\u662f1&#xff0c;\u5219\u53d61&#xff0c;\u5426\u5219\u53d60\u3002\u8fd9\u6837&#xff0c;\u6211\u4eec\u5c31\u53ef\u4ee5\u5f97\u5230\u4e8c\u8fdb\u5236\u7684k\u6700\u53f3\u4fa7\u76841\u4e86\u3002<\/p>\n<p>\u8fd9\u6837\u8bbe\u8ba1\u7684\u76ee\u7684\u662f\u4ec0\u4e48&#xff1f;<\/p>\n<p>\u6765\u770b\u770b\u6811\u72b6\u6570\u7ec4\u7684\u5f62\u72b6&#xff0c;\u8fd9\u91cc&#xff0c;\u6211\u4eec\u501f\u7528\u4e00\u4e0bB\u7ad9up\u4e3b\u9e64\u7fd4\u4e07\u91cc\u7684\u56fe&#xff0c;\u4ee5\u4e0b\u662f\u94fe\u63a5<\/p>\n<p><span class=\"link-card-box\"><span class=\"link-title\">https:\/\/www.bilibili.com\/video\/BV1pE41197Qj\/?spm_id_from&#061;333.1007.top_right_bar_window_history.content.click&amp;vd_source&#061;f8b81fa5a70ab21de75192e5c7ec720c<\/span><span class=\"link-link\"><img decoding=\"async\" class=\"link-link-icon\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250815180033-689f75c1e06e1.png\" \/>https:\/\/www.bilibili.com\/video\/BV1pE41197Qj\/?spm_id_from&#061;333.1007.top_right_bar_window_history.content.click&amp;vd_source&#061;f8b81fa5a70ab21de75192e5c7ec720c<\/span><\/span><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"483\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250815180034-689f75c272a51.png\" width=\"907\" \/><\/p>\n<p>\u5bf9\u4e8e\u6700\u5e95\u4e0b\u7684\u767d\u8272\u6570\u7ec4\u800c\u8a00(\u6ce8\u610f\u8fd9\u91cc\u7684\u6570\u7ec4a\u4e0d\u662f\u6211\u4eec\u7f16\u5199\u7684&#xff0c;\u53ea\u662f\u56fe\u7247\u7684\u4e00\u4e2a\u8303\u4f8b&#xff09;&#xff0c;\u4ed6\u8bb0\u5f55\u7684\u662f\u6211\u4eec\u5904\u7406\u8fc7\u540e\u7684\u6570\u7ec4b[\u00a0 ]&#xff0c;\u4e5f\u5c31\u662f\u5728P1\u533a\u57df\u67d0\u4e2a\u8303\u56f4\u5185\u7684\u6700\u5c0f\u503c\u3002\u73b0\u5728&#xff0c;\u6211\u4eec\u5e0c\u671b\u5728\u4e4b\u540e\u53ef\u4ee5\u66f4\u52a0\u5feb\u901f\u7684\u68c0\u7d22\u7531\u6570\u7ec4b\u751f\u6210\u7684poss\u5bf9\u5e94\u7684\u6700\u5c0f\u503c&#xff0c;\u6240\u4ee5&#xff0c;\u6211\u4eec\u6784\u5efa\u4e86\u53e6\u5916\u4e00\u4e2a\u6570\u7ec4 t [ ]\u6765\u5b58\u653e\u67d0\u4e00\u533a\u95f4&#xff08;\u8fd9\u91cc\u7684\u533a\u95f4\u6307\u7684\u662f\u7531poss\u751f\u6210\u7684\u7d22\u5f15\u533a\u95f4&#xff0c;\u56e0\u4e3aposs\u7684\u751f\u6210\u662f\u6709\u5e8f\u7684&#xff0c;\u6240\u4ee5\u533a\u95f4\u4e5f\u662f\u6709\u5e8f\u7684&#xff09;\u5185\u7684\u6700\u5c0f\u503c&#xff0c;\u5728\u6211\u4eec\u7684\u4ee3\u7801\u91cc&#xff0c;\u6570\u7ec4tree[\u00a0 ]\u7b49\u6548\u4e8e\u4e0a\u9762\u7684\u6570\u7ec4 t [\u00a0 ]\u3002<\/p>\n<p>\u6211\u4eec\u6765\u4e3e\u4f8b\u7406\u89e3\u4ed6\u5427&#xff1a;t[2]\u5b58\u50a8\u7684\u662fa[1]~a[2]\u91cc\u6bd4\u8f83\u5c0f\u7684\u90a3\u4e2a\u503c&#xff0c;t[4]\u5b58\u50a8\u7684\u662fa[1]~a[4]\u4e2d\u6700\u5c0f\u7684\u90a3\u4e2a\u503c&#xff0c;t[8]\u5b58\u50a8\u7684\u662fa[1]~a[8]\u91cc\u6700\u5c0f\u7684\u90a3\u4e2a\u503c\u3002<\/p>\n<p>\u8fd9\u79cd\u53ef\u4ee5\u901a\u8fc7\u7236\u533a\u95f4\u5feb\u901f\u67e5\u627e\u6211\u4eec\u8bbe\u5b9a\u7684\u89c4\u5219&#xff08;\u672c\u9898\u662f\u6700\u5c0f\u503c&#xff0c;\u5f53\u7136&#xff0c;\u4f60\u53ef\u4ee5\u81ea\u5df1DIY\u5b58\u50a8\u5404\u79cd\u6570\u636e\u7684\u6811\u72b6\u6570\u7ec4&#xff09;\u7684\u6811\u72b6\u7ed3\u6784&#xff0c;\u5c31\u662f\u6211\u4eec\u7684\u6811\u72b6\u6570\u7ec4\u4e86\u3002<\/p>\n<p>\u4e5f\u5c31\u662f\u8bf4&#xff0c;\u53ea\u8981\u67e5\u8be2\u5bf9\u5e94\u7684\u7236\u8282\u70b9&#xff0c;\u5c31\u53ef\u4ee5\u83b7\u6089\u5176\u7ba1\u7406\u7684\u5b50\u8282\u70b9\u7684\u6838\u5fc3\u4fe1\u606f\u3002\u5728\u67e5\u8be2\u4e4b\u524d&#xff0c;\u6811\u72b6\u6570\u7ec4\u662f\u5df2\u7ecf\u7ecf\u8fc7\u4e00\u6b21\u6bd4\u5bf9&#xff0c;\u624d\u88ab\u88ab\u6784\u5efa\u51fa\u6765\u7684&#xff0c;\u6811\u72b6\u6570\u7ec4\u5b9e\u8d28\u4e0a\u53ea\u662f\u4e3a\u4e86\u65b9\u4fbf\u540e\u7eed\u67e5\u8be2\u7684\u7ed3\u6784\u3002<\/p>\n<p>\u6811\u72b6\u6570\u7ec4\u7684\u6838\u5fc3\u601d\u60f3\u662f\u7528\u7236\u8282\u70b9\u7ba1\u7406\u82e5\u5e72\u5b50\u8282\u70b9\u7684\u4fe1\u606f&#xff0c;\u800c\u00a0lowbit\u00a0\u5c31\u662f\u7528\u6765\u786e\u5b9a\u7236\u8282\u70b9\u4e0e\u5b50\u8282\u70b9\u7684\u7ba1\u8f96\u5173\u7cfb\u7684\u5173\u952e\u3002<\/p>\n<p>\u2460lowbit\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u83b7\u5f97\u6570\u7ec4\u00a0 t [\u00a0 ]\u76ee\u524d\u7ba1\u7406\u7684\u5143\u7d20\u4e2a\u6570&#xff0c;\u4ee5\u53ca\u8ba1\u7b97\u88ab\u7ba1\u7406\u5143\u7d20\u7684\u7d22\u5f15<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<ul>\n<li>lowbit(8) &#061; 8\u00a0\u2192\u00a0t[8]\u00a0\u7ba1\u7406\u00a0a[1]~a[8]&#xff08;\u957f\u5ea6\u00a08&#xff09;<\/li>\n<li>lowbit(4) &#061; 4\u00a0\u2192\u00a0t[4]\u00a0\u7ba1\u7406\u00a0a[1]~a[4]&#xff08;\u957f\u5ea6\u00a04&#xff09;<\/li>\n<li>lowbit(6) &#061; 2\u00a0\u2192\u00a0t[6]\u00a0\u7ba1\u7406\u00a0a[5]~a[6]&#xff08;\u957f\u5ea6\u00a02&#xff09;<\/li>\n<li>lowbit(3) &#061; 1\u00a0\u2192\u00a0t[3]\u00a0\u7ba1\u7406\u00a0a[3]&#xff08;\u957f\u5ea6\u00a01&#xff09;<\/li>\n<\/ul>\n<p>\u2461lowbit\u53ef\u4ee5\u4f5c\u4e3a\u6b65\u957f\u8fdb\u884c\u8fc1\u8d8a&#xff0c;\u627e\u5230\u7236\u8282\u70b9&#xff0c;\u6216\u5b50\u8282\u70b9<\/p>\n<ul>\n<li>\u5b50\u8282\u70b9 \u2192 \u7236\u8282\u70b9&#xff1a;\u5b50\u8282\u70b9\u7684\u4e0b\u6807\u00a0i\u00a0\u52a0\u4e0a\u00a0lowbit(i)&#xff0c;\u4f1a\u8df3\u8f6c\u5230\u7236\u8282\u70b9&#xff08;\u7ba1\u7406\u66f4\u5927\u533a\u95f4&#xff09;\u3002<\/li>\n<li>\u7236\u8282\u70b9 \u2192 \u5b50\u8282\u70b9&#xff1a;\u7236\u8282\u70b9\u7684\u4e0b\u6807\u00a0i\u00a0\u51cf\u53bb\u00a0lowbit(i)&#xff0c;\u4f1a\u8df3\u8f6c\u5230\u5b50\u8282\u70b9&#xff08;\u7ba1\u7406\u66f4\u5c0f\u3001\u66f4\u7ec6\u5206\u7684\u533a\u95f4&#xff09;\u3002<\/li>\n<li>\n<h5 style=\"background-color:transparent\">\u793a\u4f8b&#xff1a;\u4fee\u6539\u00a0a[3]&#xff08;\u4e8c\u8fdb\u5236\u00a00011&#xff09;<\/h5>\n<\/li>\n<li>lowbit(3) &#061; 1&#xff08;\u4e8c\u8fdb\u5236\u00a00001&#xff09;&#xff0c;\u56e0\u6b64&#xff1a;\n<ul>\n<li>\u7b2c\u4e00\u6b65&#xff1a;\u66f4\u65b0\u00a0t[3]&#xff08;\u7ba1\u7406\u00a0a[3]&#xff09;\u2192\u00a0i &#061; 3<\/li>\n<li>\u7b2c\u4e8c\u6b65&#xff1a;i &#043;&#061; lowbit(3) \u2192 3 &#043; 1 &#061; 4\u00a0\u2192 \u66f4\u65b0\u00a0t[4]&#xff08;\u7ba1\u7406\u00a0a[1]~a[4]&#xff0c;\u5305\u542b\u00a0a[3]&#xff09;<\/li>\n<li>\u7b2c\u4e09\u6b65&#xff1a;i &#043;&#061; lowbit(4) \u2192 4 &#043; 4 &#061; 8\u00a0\u2192 \u66f4\u65b0\u00a0t[8]&#xff08;\u7ba1\u7406\u00a0a[1]~a[8]&#xff0c;\u5305\u542b\u00a0a[3]&#xff09;<\/li>\n<li>\u7b2c\u56db\u6b65&#xff1a;i &#043;&#061; lowbit(8) \u2192 8 &#043; 8 &#061; 16&#xff08;\u8d85\u51fa\u6570\u7ec4\u957f\u5ea6\u00a0n&#061;8&#xff0c;\u505c\u6b62&#xff09;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u73b0\u5728&#xff0c;\u7406\u89e3\u4e86\u57fa\u672c\u539f\u7406\u540e&#xff0c;\u6211\u4eec\u6765\u6784\u5efaupdate\u7ec4\u4ef6&#xff0c;\u4e0equery\u7ec4\u4ef6\u6df7\u5408\u4f7f\u7528\u3002<\/p>\n<p>update\u7528\u4e8e\u4e3a\u6811\u72b6\u6570\u7ec4tree\u63d2\u5165\u6570\u636e&#xff0c;\u4e5f\u5c31\u662f\u4e0a\u9762\u6811\u72b6\u6570\u7ec4\u7684\u56fe\u7247\u4e2d\u7684\u6570\u7ec4\u00a0t [\u00a0 ]\u3002<\/p>\n<p>\u2460tree\u662f\u6570\u7ec4b\u7684\u6620\u5c04&#xff0c;\u4ee5\u00a0int poss &#061; lower_bound(b.begin(), b.end(), a[i]) &#8211; b.begin() &#043; 1;\u7684\u65b9\u5f0f<\/p>\n<p>\u2461\u4f46\u6211\u4eec\u4ecd\u9700\u4ece\u6570\u7ec4a\u4e0b\u624b&#xff0c;\u56e0\u4e3a\u6570\u7ec4a\u7684\u7d22\u5f15\u4e0e\u6570\u7ec4pos\u7684\u7d22\u5f15\u662f\u4e00\u4e00\u5bf9\u5e94\u7684&#xff0c;\u6570\u7ec4tree\u53ea\u662f\u5b58\u50a8\u4e2d\u95f4\u91cf\u7684\u5de5\u5177&#xff0c;\u6211\u4eec\u4ecd\u7136\u5f97\u901a\u8fc7\u51c6\u786e\u7684\u8282\u70b9pos[i]\u6765\u8ba1\u7b97\u66fc\u54c8\u987f\u8ddd\u79bb\u3002<\/p>\n<p>\u2462tree\u5b58\u50a8\u7684\u503cval\u662f\u7279\u5f81\u503cX&#043;Y&#xff0c;\u4e5f\u5c31\u662f\u6211\u4eec\u9700\u8981\u4f20\u5165pos\u8282\u70b9\u672c\u8eab\u7684x&#xff0c;y\u4fe1\u606f<\/p>\n<p>\u8fd9\u6837\u4e00\u6765&#xff0c;update\u5c31\u9700\u8981\u4f20\u5165\u4e09\u4e2a\u6570\u636e&#xff1a;poss\u3001i\u3001\u5bf9\u5e94\u7684\u771f\u5b9e\u8282\u70b9pos[i].x\u4e0epos[i].y\u7684\u4fe1\u606f<\/p>\n<p>\u4ed6\u7684\u539f\u578b\u8bbe\u7f6e\u4e3a<\/p>\n<p>void update(int poss, int val, int id) <\/p>\n<p>\u53cd\u6b63\u8981\u8bb0\u5f55\u7279\u5f81\u503c&#xff0c;\u4e00\u4e0d\u505a\u4e8c\u4e0d\u4f11&#xff0c;\u76f4\u63a5\u5728\u4f20\u5165\u53c2\u6570\u7684\u65f6\u5019\u5c31\u8ba1\u7b97<\/p>\n<p>update(poss, pos[i].x &#043; pos[i].y, i) <\/p>\n<p>\u7136\u540e\u5f00\u59cb\u6784\u5efa\u5185\u90e8\u903b\u8f91<\/p>\n<p>\u7531\u4e8e\u4e00\u5f00\u59cb&#xff0c;tree\u6240\u6709\u5143\u7d20\u88ab\u521d\u59cb\u5316\u4e3a\u65e0\u7a77\u5927&#xff0c;\u6240\u4ee5&#xff0c;\u5f53\u6211\u4eec\u6309pos[i]\u63d2\u5165\u65f6&#xff0c;\u4ed6\u4e00\u5b9a\u662f\u6574\u4e2a\u6570\u7ec4tree\u4e2d\u6700\u5c0f\u7684\u503c&#xff0c;\u5219\u6570\u7ec4\u5fc5\u7136\u4f1a\u66f4\u65b0\u3002<\/p>\n<p>\u5728\u5f80\u540e\u7684\u64cd\u4f5c\u4e2d&#xff0c;\u4e5f\u662f\u9700\u8981\u6bd4\u5bf9\u6570\u503c&#xff0c;\u5982\u679c\u65b0\u63d2\u5165\u7684\u6570\u503c\u6bd4\u539f\u6765\u7684\u5927&#xff0c;\u5c31\u4e0d\u7ba1\u4ed6&#xff0c;\u8df3\u8fc7&#xff0c;\u4e0d\u66f4\u65b0&#xff0c;\u5982\u679c\u63d2\u5165\u7684\u6570\u503c\u66f4\u5c0f&#xff0c;\u5c31\u6309\u6b65\u957f\u5f80\u4e0b\u8d70&#xff0c;\u66f4\u65b0\u6cbf\u9014\u6240\u6709\u8282\u70b9\u7684\u503c&#xff0c;\u76f4\u5230\u8282\u70b9\u5c0f\u4e8e0\u3002<\/p>\n<p>\u5f80\u4e0b\u8d70\u7684\u539f\u56e0\u662f&#xff0c;\u6211\u4eec\u5e0c\u671b\u53ef\u4ee5\u8fd9\u4e48\u8bbe\u8ba1\u3002\u56e0\u4e3a\u8fd9\u6837\u53ef\u4ee5\u8282\u7701\u66f4\u65b0\u8282\u70b9\u7684\u65f6\u95f4\u3002\u53ef\u4ee5\u5f97\u77e5&#xff0c;\u6570\u7ec4tree\u6700\u540e\u4e00\u4e2a\u5143\u7d20&#xff0c;\u5fc5\u7136\u662f\u6574\u4e2a\u6570\u7ec4\u6700\u5c0f\u7684\u5143\u7d20&#xff0c;\u8fd9\u4e00\u70b9&#xff0c;\u53ef\u4ee5\u7531\u4e0a\u9762\u7684\u6811\u72b6\u6570\u7ec4\u56fe\u5f88\u8f7b\u6613\u7684\u83b7\u77e5\u3002<\/p>\n<p>\u6240\u4ee5\u5047\u8bbe\u6211\u4eec\u4eceX\u503c\u5927\u5230\u5c0f&#xff0c;\u4e5f\u5c31\u662f\u4ece\u6700\u672b\u5c3e\u7684\u7f16\u53f7\u5f00\u59cb\u66f4\u65b0&#xff0c;\u4ed6\u5c31\u4f1a\u4ece\u7236\u8282\u70b9\u5f00\u59cb\u66f4\u65b0&#xff0c;\u4e0d\u9700\u8981\u904d\u5386\u6240\u6709\u5b50\u8282\u70b9\u3002\u5728\u540e\u7eed\u7684\u6d41\u7a0b\u4e2d\u4e5f\u662f\u4e00\u6837\u7684\u9053\u7406\u3002\u8fd9\u6837\u4e00\u6765&#xff0c;\u904d\u5386\u4fee\u6539\u503c\u7684\u6b21\u6570\u660e\u663e\u6bd4\u4eceX\u503c\u4ece\u5c0f\u5230\u5927\u7684\u6b21\u6570\u8981\u5c0f&#xff0c;\u8282\u7701\u4e86\u4e0d\u5c11\u65f6\u95f4\u3002<\/p>\n<p>\u90a3\u4e48&#xff0c;\u6211\u4eec\u7684\u6b65\u957f\u5c31\u8bbe\u7f6e\u4e3a\u81ea\u51cf&#xff0c;\u800c\u4e0d\u662f\u6211\u4eec\u5e38\u7528\u7684\u81ea\u589e\u3002<\/p>\n<p>\u7136\u540e\u8bb0\u5f55\u6211\u4eec\u5f53\u524d\u6700\u5c0f\u503c\u7684\u8282\u70b9poss\u8eab\u4efd\u8bc1\u7f16\u53f7i,\u5b58\u50a8\u5230idRec&#xff0c;\u63a5\u7740poss\u5411\u4e0b\u904d\u5386&#xff0c;\u76f4\u81f3poss&lt;&#061;0,\u9000\u51fa\u5faa\u73af&#xff0c;\u56e0\u4e3a\u6211\u4eec\u7684\u7f16\u53f7\u662f\u4ece1\u5f00\u59cb\u7684\u3002<\/p>\n<p>    void update(int poss, int val, int id) {<br \/>\n        while (pos &gt; 0) {<br \/>\n            if (tree[poss] &gt; val) {<br \/>\n                tree[poss] &#061; val;<br \/>\n                idRec[poss] &#061; id;<br \/>\n            }<br \/>\n            poss -&#061; lowbit(poss);<br \/>\n        }<\/p>\n<p>\u7531\u4e8e\u6700\u9876\u5c42\u7684\u6570\u7ec4\u4e00\u5b9a\u662f\u6700\u5c0f\u503c&#xff0c;\u6211\u4eec\u4e5f\u53ea\u5173\u5fc3\u6700\u5c0f\u503c&#xff0c;\u5f80\u4e0b\u662f\u5982\u4f55\u5b9e\u73b0\u7684&#xff0c;\u5176\u5b9e\u6211\u4eec\u5e76\u4e0d\u9700\u8981\u5bf9\u5176\u8fc7\u591a\u5173\u6ce8<\/p>\n<p>\u73b0\u5728&#xff0c;\u6211\u4eec\u9700\u8981\u53e6\u4e00\u4e2a\u7ec4\u4ef6query\u7528\u4e8e\u67e5\u8be2\u7279\u5b9a\u533a\u57df\u6700\u5c0f\u7684\u6570\u503c\u3002\u56e0\u4e3aupdate\u53ea\u63d0\u4f9b\u63d2\u5165\u529f\u80fd&#xff0c;\u6ca1\u6709\u63d0\u4f9b\u67e5\u8be2\u529f\u80fd\u3002<\/p>\n<\/p>\n<p>\u5bf9\u4e8e\u67e5\u8be2\u529f\u80fd&#xff0c;\u6211\u4eec\u9700\u8981\u4f20\u5165\u5f53\u524dposs\u503c&#xff0c;\u627e\u5230\u5f53\u524d\u533a\u57df\u6700\u5c0f\u7684\u8fb9\u957f\u3002\u503c\u5f97\u4e00\u63d0\u7684\u662f&#xff0c;\u6811\u72b6\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u5e76\u4e0d\u4f1a\u6700\u7ec8\u90fd\u94fe\u63a5\u5230\u540c\u4e00\u4e2a\u7236\u7ed3\u70b9\u4e0a&#xff0c;\u4e00\u4e2a\u6811\u72b6\u6570\u7ec4\u6700\u7ec8\u53ef\u4ee5\u6709\u591a\u4e2a\u7236\u8282\u70b9\u3002<\/p>\n<p>\u5e78\u8fd0\u7684\u662f&#xff0c;\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7poss\u8fd9\u4e2a\u7d22\u5f15\u53ef\u4ee5\u901a\u8fc7\u81ea\u589e\u4f5c\u4e3a\u6865\u6881&#xff0c;\u6765\u8de8\u8fdb\u4e0d\u540c\u7236\u8282\u70b9\u6240\u5c5e\u7684\u6811&#xff0c;\u8fdb\u884c\u6700\u5c0f\u503c\u67e5\u8be2\u3002\u8fd9\u65f6\u5019&#xff0c;\u5c31\u7b26\u5408\u4e8c\u53c9\u7d22\u5f15\u6811\u7684\u903b\u8f91&#xff0c;\u81ea\u4e0b\u5411\u4e0a&#xff0c;\u81ea\u5de6\u5f80\u53f3\u7684\u641c\u7d22\u4e0d\u540c\u7684\u6811&#xff0c;\u5229\u7528lowbit\u6b65\u957f\u8de8\u8d8a\u7684\u529f\u80fd&#xff0c;\u6211\u4eec\u4e5f\u80fd\u5f88\u5feb\u7684\u68c0\u7d22\u5230\u6811\u72b6\u6570\u7ec4\u4e2d\u7684\u6700\u5c0f\u503c\u3002<\/p>\n<p>\u65e2\u7136\u662f\u68c0\u7d22\u6700\u5c0f\u503c&#xff0c;\u90a3\u4e48\u6211\u4eec\u5c31\u5e94\u8be5\u5b58\u5728\u8fd4\u56de\u6700\u5c0f\u503c\u7684\u529f\u80fd&#xff0c;\u4e0d\u8fc7\u7531\u4e8e\u6211\u4eec\u5b58\u50a8\u7684\u662f\u7279\u5f81\u503cval&#xff0c;\u5230\u65f6\u6211\u4eec\u8981\u5224\u65ad\u662f\u5426\u6210\u73af\u8fd8\u8981\u7528\u5230\u6bcf\u4e2a\u8282\u70b9\u81ea\u8eab\u7684\u72ec\u7acb\u6027&#xff0c;\u5426\u5219&#xff0c;\u6211\u4eec\u5c31\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528tree\u5b58\u50a8\u7684\u503c\u6765\u8ba1\u7b97\u66fc\u54c8\u987f\u8ddd\u79bb\u3002\u6240\u4ee5\u6b64\u5904&#xff0c;\u6211\u4eec\u8fd4\u56de\u539f\u59cb\u8282\u70b9\u7684\u7d22\u5f15\u3002<\/p>\n<p>\u8fd9\u91cc\u6d89\u53ca\u5230\u4e00\u4e2a\u95ee\u9898&#xff0c;\u5c31\u662f\u6700\u5c0f\u503c\u80fd\u5426\u662f\u7531\u4e0d\u540c\u7684\u70b9\u8ba1\u7b97\u51fa\u76f8\u540c\u7684\u7b54\u6848&#xff1f;\u7b54\u6848\u662f\u4e0d\u53ef\u80fd\u3002\u56e0\u4e3a\u8fdb\u5165\u6811\u7684\u8282\u70b9\u90fd\u662f\u7ecf\u8fc7Y-X\u7684\u7b5b\u9009\u7684&#xff0c;\u4e0d\u53ef\u80fd\u5728Y-X\u6bd4\u57fa\u51c6\u8282\u70b9\u5c0f\u7684\u60c5\u51b5\u4e0b&#xff0c;Y&#043;X\u7684\u503c\u4e0e\u57fa\u51c6\u8282\u70b9\u8ba1\u7b97\u7684\u76f8\u540c\u3002<\/p>\n<p>\u7136\u540e\u6211\u4eec\u5c31\u9700\u8981\u8003\u8651\u68c0\u7d22\u4e0d\u5230\u503c\u7684\u60c5\u51b5\u4e86\u3002\u5bf9\u4e8e\u68c0\u7d22\u4e0d\u5230\u503c\u7684\u60c5\u51b5&#xff0c;\u6211\u4eec\u4e5f\u5e94\u6709\u8fd4\u56de\u503c&#xff0c;\u4e3a\u4e86\u4e0e\u8282\u70b9\u7f16\u53f7\u6709\u6240\u533a\u5206&#xff0c;\u6211\u4eec\u628a\u65e0\u8fd4\u56de\u503c\u8bbe\u4e3a-1\u3002<\/p>\n<p>\u4e3a\u4e86\u53ef\u4ee5\u627e\u5230\u6700\u5c0f\u503c&#xff0c;\u4e14\u5b58\u5728\u6bd4\u5bf9\u7684\u5bf9\u8c61&#xff0c;\u6211\u4eec\u8bbe\u7528\u4e8e\u6bd4\u8f83\u7684\u503cminval\u521d\u59cb\u65f6\u662f\u65e0\u7a77\u5927\u3002<\/p>\n<p>    int query(int pos) {<br \/>\n        int minval &#061; INT_MAX;<br \/>\n        int j &#061; -1;<br \/>\n        while (pos &lt; n) {<br \/>\n            if (minval &gt; tree[pos]) {<br \/>\n                minval &#061; tree[pos];<br \/>\n                j &#061; idRec[pos];<br \/>\n            }<br \/>\n            pos &#043;&#061; lowbit(pos);<br \/>\n        }<br \/>\n        return j;<br \/>\n    } <\/p>\n<p>\u73b0\u5728&#xff0c;\u6211\u4eec\u5df2\u7ecf\u5b8c\u6210\u4e86\u5bf9\u4e8c\u53c9\u7d22\u5f15\u6811\u7684\u5168\u90e8\u6784\u5efa&#xff0c;\u6765\u4e00\u5f20\u5168\u5bb6\u798f\u5427\u3002<\/p>\n<p>class BIT {<br \/>\npublic:<br \/>\n    vector&lt;int&gt; tree, idRec;<br \/>\n    int n;<\/p>\n<p>    BIT(int _n) {<br \/>\n        n &#061; _n;<br \/>\n        tree.resize(n, INT_MAX);<br \/>\n        idRec.resize(n, -1);<br \/>\n    }<\/p>\n<p>    int lowbit(int k) { return k &amp; (-k); }<\/p>\n<p>    void update(int pos, int val, int id) {<br \/>\n        while (pos &gt; 0) {<br \/>\n            if (tree[pos] &gt; val) {<br \/>\n                tree[pos] &#061; val;<br \/>\n                idRec[pos] &#061; id;<br \/>\n            }<br \/>\n            pos -&#061; lowbit(pos);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    int query(int pos) {<br \/>\n        int minval &#061; INT_MAX;<br \/>\n        int j &#061; -1;<br \/>\n        while (pos &lt; n) {<br \/>\n            if (minval &gt; tree[pos]) {<br \/>\n                minval &#061; tree[pos];<br \/>\n                j &#061; idRec[pos];<br \/>\n            }<br \/>\n            pos &#043;&#061; lowbit(pos);<br \/>\n        }<br \/>\n        return j;<br \/>\n    }<br \/>\n}; <\/p>\n<p>\u4e8c\u53c9\u7d22\u5f15\u6811\u53ea\u662f\u5b8c\u6210\u4e86\u5bf9\u533a\u57df\u6700\u5c0f\u8fb9\u7684\u9009\u62e9&#xff0c;\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u53e6\u5916\u4e00\u4e2a\u7ec4\u4ef6&#xff0c;\u6765\u5229\u7528\u4e8c\u53c9\u7d22\u5f15\u6811\u6784\u5efa\u8fb9\u3002<\/p>\n<p>\u662f\u7684&#xff0c;\u5230\u8fd9\u91cc\u7b14\u8005\u5df2\u7ecf\u5199\u4e8612000\u5b57\u7684\u601d\u8def\u4e86\u00a0&#xff0c;\u624d\u521a\u5230\u8fb9\u7684\u6784\u5efa\u3002\u54c8\u54c8&#xff0c;\u4e0d\u8fc7\u5be5\u5be5\u4e00\u767e\u591a\u884c\u7684\u4ee3\u7801&#xff0c;\u5c45\u7136\u6709\u8fd9\u4e48\u591a\u95e8\u9053\u3002\u5e9e\u6742\u7684\u601d\u8def\u88ab\u6d53\u7f29\u6210\u7cbe\u7b80\u7684\u4ee3\u7801&#xff0c;\u771f\u662f\u8ba9\u4eba\u7740\u8ff7\u3002<\/p>\n<p>\u4e3a\u4e86\u7f16\u5199\u6784\u9020\u8fb9\u7684\u7ec4\u4ef6&#xff0c;\u6211\u4eec\u9700\u8981\u53e6\u8bbe\u4e00\u4e2a\u51fd\u6570&#xff0c;\u5c31\u7ba1\u4ed6\u53ebbuild\u5427\u3002<\/p>\n<p>\u5728\u8fdb\u884cbuild\u4e4b\u524d&#xff0c;\u6211\u4eec\u9700\u8981\u77e5\u9053\u4fdd\u7559\u7684\u8fb9\u7684\u4fe1\u606f&#xff1a;<\/p>\n<p>\u7b2c\u4e00&#xff1a;\u6784\u5efa\u4ed6\u6700\u4e3b\u8981\u7684\u76ee\u7684\u662f\u77e5\u9053\u8fb9\u7684\u957f\u5ea6<\/p>\n<p>\u7b2c\u4e8c&#xff1a;\u6211\u4eec\u4e0d\u5e0c\u671b\u5b83\u6210\u73af&#xff0c;\u6240\u4ee5\u6211\u4eec\u5e0c\u671b\u8bb0\u5f55\u8fb9\u7684\u540c\u65f6&#xff0c;\u53ef\u4ee5\u540c\u6b65\u8bb0\u5f55\u6784\u6210\u5b83\u7684\u4e24\u4e2a\u8282\u70b9\u7684\u7f16\u53f7<\/p>\n<p>\u7b2c\u4e09&#xff1a;\u6211\u4eec\u77e5\u9053&#xff0c;\u540e\u9762\u4f1a\u6709\u5bb9\u5668\u5b58\u50a8\u8fb9\u7684\u4fe1\u606f&#xff0c;\u800c\u4e14\u9700\u8981\u9009\u53d6\u6700\u5c0f\u503c\u3002\u4f46\u5b58\u50a8\u4e86\u8fd9\u4e48\u591a\u4fe1\u606f\u7684\u4e2a\u4f53&#xff0c;\u9700\u8981\u4e00\u4e2a\u4e3b\u5bfc\u5143\u7d20\u6765\u4f9b\u7ed9\u6bd4\u8f83&#xff0c;\u8fd9\u4e2a\u4e3b\u5bfc\u5143\u7d20\u5c31\u662f\u66fc\u54c8\u987f\u957f\u5ea6\u3002<\/p>\n<p>\u57fa\u4e8e\u4e0a\u8ff0\u8981\u6c42&#xff0c;\u6784\u5efa\u7ed3\u6784\u4f53\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9&#xff0c;\u63a5\u7740&#xff0c;\u4e3a\u4e86\u6ee1\u8db3\u6bd4\u8f83\u7684\u9700\u6c42&#xff0c;\u6211\u4eec\u9700\u8981\u91cd\u8f7d\u8fd0\u7b97\u7b26\u6765\u4f9b\u7ed9\u540e\u9762\u7684\u6392\u5e8f\u9700\u8981\u3002<\/p>\n<p>struct Edge {<br \/>\n    int len, i, j;<br \/>\n    Edge(int len, int i, int j) : len(len), i(i), j(j) {<br \/>\n    }<br \/>\n    bool operator&lt;(const Edge&amp; a) const {<br \/>\n        return len &lt; a.len;<br \/>\n    }<br \/>\n}; <\/p>\n<p>\u8fd9\u91cc\u9700\u8981\u6ce8\u610f\u7684\u662f&#xff0c;\u91cd\u8f7d\u8fd0\u7b97\u7b26\u524d\u540e\u90fd\u6709\u4e00\u4e2aconst\u3002<\/p>\n<p>\u524d\u9762\u7684const&#xff0c;\u662f\u4e3a\u4e86\u4fdd\u8bc1\u4f20\u5165\u7684\u53c2\u6570\u4e0d\u88ab\u4fee\u6539<\/p>\n<p>\u540e\u9762\u7684const&#xff0c;\u662f\u4e3a\u4e86\u4fdd\u8bc1this\u6307\u9488\u6240\u6307\u7684\u5bf9\u8c61\u53c2\u6570\u4e0d\u88ab\u4fee\u6539<\/p>\n<p>\u65e2\u7136\u5b8c\u6210\u4e86\u5bf9\u8fb9\u7684\u6784\u5efa&#xff0c;\u6211\u4eec\u5c31\u9700\u8981\u6709\u4e00\u4e2a\u5bb9\u5668\u6765\u5b58\u50a8\u751f\u6210\u7684\u8fb9<\/p>\n<p>  vector&lt;Edge&gt; edges; <\/p>\n<p>\u5bf9\u4e8ebuild&#xff0c;\u65e2\u7136\u5b83\u662f\u6784\u5efa\u8fb9\u7684\u51fd\u6570&#xff0c;\u90a3\u4ed6\u5c31\u5e94\u8be5\u5305\u62ec\u6211\u4eec\u6784\u5efa\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u6240\u6709\u64cd\u4f5c&#xff0c;\u56e0\u4e3a\u8fd9\u672c\u5c31\u662f\u4e3a\u4ed6\u670d\u52a1\u7684\u3002<\/p>\n<p>\u6211\u4eec\u6574\u7406\u4e00\u4e0b\u601d\u8def\u5427&#xff1a;<\/p>\n<p>\u2460\u5bf9\u6240\u6709\u8282\u70b9pos\u6309\u7167X\u503c\u7531\u5c0f\u5230\u5927\u6392\u5e8f<\/p>\n<p>\u2461\u8bbe\u7acb\u4e24\u4e2a\u6570\u7ec4a\u4e0eb<\/p>\n<p>\u2462\u5bf9b\u8fdb\u884c\u53bb\u91cd<\/p>\n<p>\u2463\u4ee5b\u7684\u5927\u5c0f\u4e3aBIT\u6784\u5efa\u5b9e\u4f8b<\/p>\n<p>\u2464\u8fdb\u5165\u5faa\u73af&#xff0c;\u7531\u7f16\u53f7\u4ece\u5927\u5230\u5c0f\u4e3aBIT\u66f4\u65b0\u6700\u5c0f\u503c<\/p>\n<p>\u2465\u4f7f\u7528query\u641c\u67e5\u6700\u5c0f\u503c<\/p>\n<p>\u2466\u82e5\u662f\u641c\u67e5\u5230\u6700\u5c0f\u503c\u5c31\u8ba1\u7b97\u66fc\u54c8\u987f\u8ddd\u79bb&#xff0c;\u5c06\u5176\u585e\u5165\u6570\u7ec4edges\u4e2d&#xff0c;\u4f9b\u7ed9Kruskal\u7b97\u6cd5\u5907\u9009<\/p>\n<p>\u2467\u65e0\u8bba\u662f\u5426\u5b58\u5728\u6700\u5c0f\u8fb9&#xff0c;\u90fd\u4ee5\u5f53\u524d\u5faa\u73af\u7684\u7f16\u53f7\u4f7f\u7528update\u585e\u5165\u65b0\u8282\u70b9\u8fdbBIT<\/p>\n<p>\u2468\u8fdb\u5165\u4e0b\u4e00\u8f6e\u5faa\u73af&#xff0c;\u91cd\u590d\u2464~\u2467&#xff0c;\u76f4\u81f3\u6240\u6709\u5143\u7d20\u88ab\u5904\u7406\u5b8c\u6210\u3002<\/p>\n<p>\u8fd9\u91cc\u6211\u4eec\u603b\u662f\u53ea\u8003\u8651\u533a\u57dfP1&#xff0c;\u6240\u4ee5\u8fd9\u4e2a\u51fd\u6570\u5e94\u8be5\u8fd8\u88ab\u522b\u7684\u51fd\u6570\u6240\u4f7f\u7528&#xff0c;\u8fd9\u91cc\u6211\u4eec\u53ea\u4f20\u5165\u53c2\u6570n\u6765\u8ba9\u4e0b\u8ff0\u64cd\u4f5c\u6b63\u786e\u6784\u9020\u6570\u7ec4\u5373\u53ef&#xff0c;\u5176\u4ed6\u53c2\u6570\u7531\u8c03\u7528build\u7684\u51fd\u6570\u6765\u63d0\u4f9b\u3002<\/p>\n<p>\u4e3a\u4ec0\u4e48\u8981\u8fd9\u4e48\u505a&#xff1f;<\/p>\n<p>\u56e0\u4e3a\u5728build\u51fd\u6570\u4e2d\u65e0\u8bba\u4ec0\u4e48\u60c5\u51b5&#xff0c;\u90fd\u53ea\u6709n&#xff0c;\u4ee5\u53ca\u6bcf\u4e2a\u8282\u70b9\u7684pos[i].x\u4e0epos[i].y\u662f\u4e0d\u53d8\u7684&#xff0c;\u4e14n\u662f\u4e00\u4e2a\u53c2\u6570&#xff0c;\u4e0d\u4f1a\u5f71\u54cd\u7a0b\u5e8f\u8fd0\u884c\u901f\u5ea6\u3002\u4f46\u82e5\u662f\u6bcf\u6b21n\u90fd\u4f20\u5165pos\u7684\u8bdd&#xff0c;\u9ebb\u70e6\u5c31\u5927\u4e86\u3002\u56e0\u4e3apos\u5b9e\u9645\u4e0a\u662f\u6211\u4eec\u5bf9\u4f20\u5165\u7684vector&lt;vector&lt;int&gt;&gt;&amp; points\u7684\u4e00\u79cd\u6539\u9020&#xff0c;\u5982\u679c\u6bcf\u6b21\u4f7f\u7528pos&#xff0c;\u90fd\u8981\u4f20\u5165\u4e00\u6b21points\u6570\u7ec4\u8fdb\u884c\u8d4b\u503c\u7684\u8bdd&#xff0c;\u7a0b\u5e8f\u5c31\u4f1a\u53d8\u7684\u5947\u6162\u65e0\u6bd4\u3002\u6240\u4ee5\u6211\u4eec\u5e0c\u671b\u53ea\u5bf9pos\u8d4b\u503c\u4e00\u6b21\u5c31\u591f\u4e86&#xff0c;\u540e\u9762\u5c31\u53ef\u4ee5\u5c3d\u60c5\u7684\u4f7f\u7528\u5b83&#xff0c;\u800c\u4e0d\u662f\u6bcf\u8c03\u7528\u4e00\u6b21build\u5c31\u6784\u9020\u4e00\u6b21pos\u3002<\/p>\n<p>    void build(int n) {<br \/>\n        sort(pos.begin(), pos.end());<br \/>\n        vector&lt;int&gt; a(n), b(n);<br \/>\n        for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n            a[i] &#061; pos[i].y &#8211; pos[i].x;<br \/>\n            b[i] &#061; pos[i].y &#8211; pos[i].x;<br \/>\n        }<br \/>\n        sort(b.begin(), b.end());<br \/>\n        b.erase(unique(b.begin(), b.end()), b.end());<br \/>\n        int num &#061; b.size();<br \/>\n        BIT bit(num &#043; 1);<br \/>\n        for (int i &#061; n &#8211; 1; i &gt;&#061; 0; i&#8211;) {<br \/>\n            int poss &#061; lower_bound(b.begin(), b.end(), a[i]) &#8211; b.begin() &#043; 1;<br \/>\n            int j &#061; bit.query(poss);<br \/>\n            if (j !&#061; -1) {<br \/>\n                int dis &#061; abs(pos[i].x &#8211; pos[j].x) &#043; abs(pos[i].y &#8211; pos[j].y);<br \/>\n                edges.emplace_back(dis, pos[i].id, pos[j].id);<br \/>\n            }<br \/>\n            bit.update(poss, pos[i].x &#043; pos[i].y, i);<br \/>\n        }<br \/>\n    }<\/p>\n<p>\u00a0\u9700\u8981\u6ce8\u610f\u7684\u662f&#xff0c;\u66fc\u54c8\u987f\u8ddd\u79bb\u662f\u4e00\u4e2a\u7edd\u5bf9\u503c&#xff0c;\u6240\u4ee5\u9700\u8981\u7528\u5230abs&#xff08;&#xff09;\u51fd\u6570\u53d6\u7edd\u5bf9\u503c<\/p>\n<\/p>\n<p>\u63a5\u4e0b\u6765&#xff0c;\u5c31\u53ea\u5269\u4e0b\u6700\u540e\u4e00\u4e2a\u7ec4\u4ef6\u4e86<\/p>\n<p>\u7531\u4e8e\u6211\u4eec\u4ee5\u4e0a\u64cd\u4f5c&#xff0c;\u90fd\u9ed8\u8ba4\u662f\u5728P1\u533a\u57df\u8fdb\u884c\u7684&#xff0c;\u800c\u6211\u4eec\u9700\u8981\u751f\u6210P1&#xff0c;P2&#xff0c;P3&#xff0c;P4\u56db\u4e2a\u533a\u57df\u7684\u8fb9&#xff0c;\u663e\u7136&#xff0c;\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u51fd\u6570\u6765\u4e3a\u6211\u4eec\u8fbe\u6210\u8fd9\u4e2a\u76ee\u7684&#xff0c;\u4f7f\u4e4b\u590d\u7528\u4e0a\u9762\u7684build\u51fd\u6570\u6765\u5b8c\u6210\u56db\u4e2a\u533a\u57df\u6240\u6709\u8fb9\u7684\u751f\u6210&#xff0c;\u5c31\u53eb\u5b83MST\u5427<\/p>\n<p>\u6211\u4eec\u4ee5\u4e0a\u64cd\u4f5c&#xff0c;\u90fd\u662f\u57fa\u4e8e\u9898\u76ee\u4f20\u5165\u7684\u6570\u7ec4\u548c\u8282\u70b9\u4e2a\u6570\u5b9e\u73b0\u7684\u3002\u4e3a\u4e86\u8fbe\u6210\u8fb9\u751f\u6210\u7684\u76ee\u7684&#xff0c;\u8fd9\u4e9b\u4fe1\u606f\u4e5f\u5fc5\u4e0d\u53ef\u5c11&#xff0c;\u6240\u4ee5\u9664\u4e86\u4f20\u5165\u7684points\u6570\u7ec4\u4e4b\u5916&#xff0c;\u6211\u4eec\u9700\u8981\u83b7\u53d6\u6570\u7ec4\u4e2a\u6570\u7684\u53c2\u6570<\/p>\n<p>  void MST(vector&lt;vector&lt;int&gt;&gt;&amp; points, int n) <\/p>\n<p>\u4ed6\u6ca1\u6709\u8fd4\u56de\u503c&#xff0c;\u56e0\u4e3a\u4ed6\u53ea\u662f\u8c03\u7528build\u51fd\u6570\u751f\u6210\u8fb9\u800c\u5df2<\/p>\n<p>\u9996\u5148&#xff0c;\u6211\u4eec\u9700\u8981\u4e3abuild\u51fd\u6570\u63d0\u4f9b\u5b83\u9700\u8981\u7684pos\u8282\u70b9\u4fe1\u606f<\/p>\n<p>        pos.resize(n);<br \/>\n        for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n            pos[i].x &#061; points[i][0];<br \/>\n            pos[i].y &#061; points[i][1];<br \/>\n            pos[i].id &#061; i;<br \/>\n        } <\/p>\n<p>\u6784\u9020\u5bf9pos\u6570\u7ec4\u8fdb\u884c\u91cd\u6784&#xff0c;\u4f7f\u4e4b\u5927\u5c0f\u4e3an&#xff0c;\u7136\u540e\u5229\u7528\u4f20\u5165\u7684\u4e8c\u7ef4\u6570\u7ec4\u8d4b\u503c&#xff0c;\u5c06\u5176\u8868\u793a\u4e3ax&#xff0c;y&#xff0c;\u5e76\u8d4b\u4e88\u8fd9\u4e9b\u8282\u70b9\u72ec\u7279\u7f16\u53f7&#xff0c;\u4ee5\u4fbf\u6211\u4eec\u4f7f\u7528\u5e76\u67e5\u96c6\u65f6\u53ef\u4ee5\u63a2\u67e5\u662f\u5426\u6210\u73af&#xff0c;\u4ee5\u53ca\u4f7f\u7528BIT\u65f6\u6709\u68c0\u7d22\u7684\u76ee\u6807\u3002<\/p>\n<p>\u7136\u540e\u4f9d\u6b21\u6784\u5efaP1&#xff0c;P2&#xff0c;P3&#xff0c;P4\u533a\u57df\u7684\u8fb9<\/p>\n<p>P1&#xff1a;\u76f4\u63a5\u8c03\u7528build\u51fd\u6570\u5373\u53ef&#xff0c;\u56e0\u4e3a\u6211\u4eec\u9ed8\u8ba4\u5c31\u662f\u8bbe\u5b9aP1\u4e3a\u793a\u4f8b\u533a\u57df<\/p>\n<p>      build(n); <\/p>\n<p>P2&#xff1a;\u65e2\u7136build\u7684\u9ed8\u8ba4\u5904\u7406\u65b9\u5f0f\u662fP1&#xff0c;\u90a3\u6211\u4eec\u5c31\u628aP2\u4e5f\u5316\u6210P1\u533a\u57df\u7684\u6a21\u6837\u5c31\u597d\u4e86&#xff0c;\u6211\u4eec\u53ea\u9700\u8981\u5bf9\u5750\u6807\u8fdb\u884c\u4e00\u4e9b\u53d8\u5316&#xff0c;\u6bd4\u5982\u8bf4&#xff1a;\u7ffb\u8f6c<\/p>\n<p>\u73b0\u5728&#xff0c;X\u4e0eY\u90fd\u662f\u6b63\u6570&#xff0c;\u4e14P1\u533a\u57df\u662f\u9ecf\u5728Y\u8f74\u4e0a\u7684&#xff0c;\u800cP2\u662f\u9ecf\u5728X\u8f74\u4e0a\u7684&#xff0c;\u4e14\u6761\u4ef6\u4e5f\u662fX\u4e0eY\u90fd\u662f\u6b63\u6570\u3002<\/p>\n<p>\u806a\u660e\u7684\u4f60\u5df2\u7ecf\u60f3\u5230\u4e86&#xff0c;\u6211\u53ea\u9700\u8981\u4ea4\u6362X\u4e0eY\u7684\u5730\u4f4d&#xff0c;\u5c31\u53ef\u4ee5\u4ee4P2\u533a\u57df\u50cfP1\u533a\u57df\u4e00\u6837\u5904\u7406\u4e86<\/p>\n<p>       for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n            swap(pos[i].x, pos[i].y);<br \/>\n        }<br \/>\n        build(n); <\/p>\n<p>P3&#xff1a;\u6211\u4eec\u77e5\u9053&#xff0c;P3\u4e0eP2\u5728\u539f\u6765\u7684\u5750\u6807\u8f74\u4e2d\u662f\u4ee5X\u8f74\u5bf9\u79f0\u7684&#xff0c;\u73b0\u5728X\u4e0eY\u6570\u503c\u4ea4\u6362<\/p>\n<p>\u672c\u6765\u5e94\u8be5\u662f\u65cb\u8f6cX\u8f74\u7684\u64cd\u4f5c&#xff0c;\u73b0\u5728\u5e94\u8be5\u53d8\u6210\u65cb\u8f6cY\u8f74&#xff0c;\u6b64\u65f6Y\u8f74\u7531pos[i].x\u8868\u793a&#xff0c;\u65cb\u8f6c\u5b83&#xff0c;\u5373\u8ba9\u5176\u53d8\u4e3a\u8d1f\u7684<\/p>\n<p>        for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n            pos[i].x &#061; -pos[i].x;<br \/>\n        }<br \/>\n        build(n); <\/p>\n<p>P4&#xff1a;\u7531\u4e8e\u73b0\u5728P3\u7b49\u6548\u4e8eP1&#xff0c;\u90a3\u4e48P4\u5c31\u7b49\u6548\u4e3aP2.\u60f3\u60f3\u4ee5P1\u4e3a\u57fa\u51c6\u65f6&#xff0c;\u5bf9P2\u600e\u4e48\u64cd\u4f5c\u7684\u5427&#xff1a;\u4ea4\u6362X\u548cY\u7684\u503c\u3002\u90a3\u4e48\u73b0\u5728\u6211\u4eec\u4e5f\u8981\u5bf9P4\u8fdb\u884c\u540c\u7b49\u64cd\u4f5c&#xff0c;\u8ba9\u4ed6\u53d8\u6210P1\u7684\u5f62\u72b6\u3002<\/p>\n<p>        build(n);<br \/>\n        for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n            swap(pos[i].x, pos[i].y);<br \/>\n        }<br \/>\n        build(n); <\/p>\n<p>\u4ee5\u4e0b\u662f\u5b8c\u6574\u7684MST\u51fd\u6570\u5b9e\u73b0<\/p>\n<p>    void MST(vector&lt;vector&lt;int&gt;&gt;&amp; points, int n) {<br \/>\n        pos.resize(n);<br \/>\n        for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n            pos[i].x &#061; points[i][0];<br \/>\n            pos[i].y &#061; points[i][1];<br \/>\n            pos[i].id &#061; i;<br \/>\n        }<br \/>\n        build(n);<br \/>\n        for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n            swap(pos[i].x, pos[i].y);<br \/>\n        }<br \/>\n        build(n);<br \/>\n        for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n            pos[i].x &#061; -pos[i].x;<br \/>\n        }<br \/>\n        build(n);<br \/>\n        for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n            swap(pos[i].x, pos[i].y);<br \/>\n        }<br \/>\n        build(n);<br \/>\n    } <\/p>\n<h2 style=\"text-align:center\"><span style=\"color:#fe2c24\">\u6211\u5df2\u7ecf\u4ec0\u4e48\u90fd\u4e0d\u7f3a\u4e86<\/span><\/h2>\n<p>\u6765\u6784\u5efa\u9898\u76ee\u7684\u8c03\u7528\u51fd\u6570\u5427&#xff0c;\u4ed6\u5df2\u7ecf\u7ed9\u4e86\u57fa\u672c\u683c\u5f0f\u4e86<\/p>\n<p>    int minCostConnectPoints(vector&lt;vector&lt;int&gt;&gt;&amp; points) <\/p>\n<p>\u73b0\u5728&#xff0c;\u6211\u4eec\u9700\u8981\u6309\u6d41\u7a0b\u8c03\u7528\u6211\u4eec\u4e0a\u9762\u6240\u6709\u7684\u7ec4\u4ef6<\/p>\n<p>\u2460\u83b7\u53d6\u5143\u7d20\u4e2a\u6570n&#xff0c;\u8fd9\u5e94\u8be5\u5728\u8c03\u7528\u51fd\u6570\u4e4b\u5916\u8fdb\u884c&#xff0c;\u56e0\u4e3a\u6240\u6709\u51fd\u6570\u90fd\u7528\u5230\u4e86\u5b83&#xff0c;\u4ed6\u5fc5\u987b\u662f\u4e2a\u5168\u5c40\u53d8\u91cf<\/p>\n<p>\u2461\u751f\u6210\u6240\u6709\u53ef\u7528\u7684\u8fb9&#xff0c;\u8c03\u7528MST\u51fd\u6570<\/p>\n<p>\u2462\u521d\u59cb\u5316\u5e76\u67e5\u96c6&#xff0c;\u8c03\u7528DisjointSetUnion\u7c7b\u7684\u6784\u9020\u51fd\u6570<\/p>\n<p>\u2463\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u8fd4\u56de\u503c&#xff0c;\u521d\u59cb\u6210\u672cret\u4e3a0&#xff0c;\u7136\u540e\u4e00\u4e2a\u7528\u4e8e\u8ba1\u6570\u7684\u5b9e\u4f8bnum&#xff0c;\u7528\u4e8e\u8bb0\u5f55\u6b64\u65f6\u63d2\u5165\u7684\u8282\u70b9\u4e2a\u6570&#xff0c;\u65b9\u4fbf\u540e\u7eed\u5224\u65ad\u662f\u5426\u6240\u6709\u8282\u70b9\u5df2\u7ecf\u63d2\u5165&#xff0c;\u7136\u540e\u53ef\u4ee5\u7ec8\u6b62\u7a0b\u5e8f\u3002\u6ce8\u610f&#xff0c;num\u88ab\u521d\u59cb\u5316\u4e3a1&#xff0c;\u56e0\u4e3a\u6bcf\u9009\u7528\u4e00\u6761\u8fb9&#xff0c;\u610f\u5473\u7740\u7eb3\u5165\u4e00\u4e2a\u8282\u70b9\u3002\u867d\u7136\u6709\u65f6\u5019\u9009\u53d6\u7684\u8fb9\u94fe\u63a5\u7684\u8282\u70b9\u5e76\u4e0d\u5904\u4e8e\u6211\u4eec\u4e4b\u524d\u7684\u7236\u8282\u70b9\u91cc\u9762&#xff0c;\u5f62\u6210\u4e24\u68f5\u6811&#xff0c;\u4f46\u5b83\u6700\u540e\u603b\u662f\u4f1a\u6210\u4e3a\u4e00\u4e2a\u6574\u4f53\u7684&#xff0c;\u6240\u4ee5\u521d\u59cb\u4e3a1\u662f\u5f88\u5408\u7406\u7684\u3002<\/p>\n<p>\u2464\u628aMST\u51fd\u6570\u6240\u6709\u751f\u6210\u7684\u8fb9\u4ece\u5c0f\u5230\u5927\u6392\u5e8f<\/p>\n<p>\u2465\u904d\u5386\u6574\u4e2aedges&#xff0c;\u5373\u5b58\u50a8\u6700\u5c0f\u8fb9\u7684\u6570\u7ec4<\/p>\n<p>\u2466\u5229\u7528\u5e76\u67e5\u96c6\u5224\u65ad\u5176\u662f\u5426\u6210\u73af&#xff0c;\u6210\u73af&#xff0c;\u5e76\u67e5\u96c6\u8fd4\u56defalse&#xff0c;\u8fdb\u884c\u4e0b\u4e00\u6b21\u5faa\u73af<\/p>\n<p>\u2467\u4e0d\u6210\u73af&#xff0c;\u7d2f\u52a0\u5f53\u524d\u8fb9\u7684\u957f\u5ea6ret&#xff0c;num\u8ba1\u6570\u52a0\u4e00<\/p>\n<p>\u2468\u5224\u65adnum\u662f\u5426\u7b49\u4e8en&#xff0c;\u5373\u662f\u5426\u6240\u6709\u70b9\u90fd\u5df2\u7ecf\u52a0\u5165&#xff0c;\u82e5\u662f&#xff0c;\u7ec8\u6b62\u7a0b\u5e8f&#xff0c;\u8fd4\u56de\u6210\u672cret<\/p>\n<p>\u2469\u82e5\u6240\u6709\u8282\u70b9\u4ecd\u672a\u52a0\u5165\u6811\u4e2d&#xff0c;\u5faa\u73af\u2465~\u2468&#xff0c;\u76f4\u81f3\u7a0b\u5e8f\u7ec8\u6b62&#xff0c;\u8fd4\u56de\u6210\u672cret<\/p>\n<p>\u8fd9\u5c31\u662f\u6240\u6709\u4e86<\/p>\n<p>\u5199\u7684\u6700\u957f\u7684\u4e00\u6b21&#xff0c;\u524d\u9762\u6240\u6709\u6587\u7ae0\u7684\u5b57\u6570\u52a0\u8d77\u6765\u7ffb\u4e00\u500d\u90fd\u6ca1\u6709\u8fd9\u4e00\u7bc7\u957f\u3002<\/p>\n<p>\u6700\u540e&#xff0c;\u9644\u4e0a\u529b\u6263\u5b98\u65b9\u7684\u5b8c\u6574\u9898\u89e3<\/p>\n<p>\u4f5c\u8005&#xff1a;\u529b\u6263\u5b98\u65b9\u9898\u89e3<\/p>\n<p>\u94fe\u63a5&#xff1a;https:\/\/leetcode.cn\/problems\/min-cost-to-connect-all-points\/solutions\/565801\/lian-jie-suo-you-dian-de-zui-xiao-fei-yo-kcx7\/<\/p>\n<p>\u6765\u6e90&#xff1a;\u529b\u6263&#xff08;LeetCode&#xff09;<\/p>\n<p>\u8457\u4f5c\u6743\u5f52\u4f5c\u8005\u6240\u6709\u3002\u5546\u4e1a\u8f6c\u8f7d\u8bf7\u8054\u7cfb\u4f5c\u8005\u83b7\u5f97\u6388\u6743&#xff0c;\u975e\u5546\u4e1a\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904\u3002<\/p>\n<p>class DisjointSetUnion {<br \/>\nprivate:<br \/>\n    vector&lt;int&gt; f, rank;<br \/>\n    int n;<\/p>\n<p>public:<br \/>\n    DisjointSetUnion(int _n) {<br \/>\n        n &#061; _n;<br \/>\n        rank.resize(n, 1);<br \/>\n        f.resize(n);<br \/>\n        for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n            f[i] &#061; i;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    int find(int x) {<br \/>\n        return f[x] &#061;&#061; x ? x : f[x] &#061; find(f[x]);<br \/>\n    }<\/p>\n<p>    int unionSet(int x, int y) {<br \/>\n        int fx &#061; find(x), fy &#061; find(y);<br \/>\n        if (fx &#061;&#061; fy) {<br \/>\n            return false;<br \/>\n        }<br \/>\n        if (rank[fx] &lt; rank[fy]) {<br \/>\n            swap(fx, fy);<br \/>\n        }<br \/>\n        rank[fx] &#043;&#061; rank[fy];<br \/>\n        f[fy] &#061; fx;<br \/>\n        return true;<br \/>\n    }<br \/>\n};<\/p>\n<p>class BIT {<br \/>\npublic:<br \/>\n    vector&lt;int&gt; tree, idRec;<br \/>\n    int n;<\/p>\n<p>    BIT(int _n) {<br \/>\n        n &#061; _n;<br \/>\n        tree.resize(n, INT_MAX);<br \/>\n        idRec.resize(n, -1);<br \/>\n    }<\/p>\n<p>    int lowbit(int k) {<br \/>\n        return k &amp; (-k);<br \/>\n    }<\/p>\n<p>    void update(int pos, int val, int id) {<br \/>\n        while (pos &gt; 0) {<br \/>\n            if (tree[pos] &gt; val) {<br \/>\n                tree[pos] &#061; val;<br \/>\n                idRec[pos] &#061; id;<br \/>\n            }<br \/>\n            pos -&#061; lowbit(pos);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    int query(int pos) {<br \/>\n        int minval &#061; INT_MAX;<br \/>\n        int j &#061; -1;<br \/>\n        while (pos &lt; n) {<br \/>\n            if (minval &gt; tree[pos]) {<br \/>\n                minval &#061; tree[pos];<br \/>\n                j &#061; idRec[pos];<br \/>\n            }<br \/>\n            pos &#043;&#061; lowbit(pos);<br \/>\n        }<br \/>\n        return j;<br \/>\n    }<br \/>\n};<\/p>\n<p>struct Edge {<br \/>\n    int len, x, y;<br \/>\n    Edge(int len, int x, int y) : len(len), x(x), y(y) {<br \/>\n    }<br \/>\n    bool operator&lt;(const Edge&amp; a) const {<br \/>\n        return len &lt; a.len;<br \/>\n    }<br \/>\n};<\/p>\n<p>struct Pos {<br \/>\n    int id, x, y;<br \/>\n    bool operator&lt;(const Pos&amp; a) const {<br \/>\n        return x &#061;&#061; a.x ? y &lt; a.y : x &lt; a.x;<br \/>\n    }<br \/>\n};<\/p>\n<p>class Solution {<br \/>\npublic:<br \/>\n    vector&lt;Edge&gt; edges;<br \/>\n    vector&lt;Pos&gt; pos;<\/p>\n<p>    void build(int n) {<br \/>\n        sort(pos.begin(), pos.end());<br \/>\n        vector&lt;int&gt; a(n), b(n);<br \/>\n        for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n            a[i] &#061; pos[i].y &#8211; pos[i].x;<br \/>\n            b[i] &#061; pos[i].y &#8211; pos[i].x;<br \/>\n        }<br \/>\n        sort(b.begin(), b.end());<br \/>\n        b.erase(unique(b.begin(), b.end()), b.end());<br \/>\n        int num &#061; b.size();<br \/>\n        BIT bit(num &#043; 1);<br \/>\n        for (int i &#061; n &#8211; 1; i &gt;&#061; 0; i&#8211;) {<br \/>\n            int poss &#061; lower_bound(b.begin(), b.end(), a[i]) &#8211; b.begin() &#043; 1;<br \/>\n            int j &#061; bit.query(poss);<br \/>\n            if (j !&#061; -1) {<br \/>\n                int dis &#061; abs(pos[i].x &#8211; pos[j].x) &#043; abs(pos[i].y &#8211; pos[j].y);<br \/>\n                edges.emplace_back(dis, pos[i].id, pos[j].id);<br \/>\n            }<br \/>\n            bit.update(poss, pos[i].x &#043; pos[i].y, i);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    void solve(vector&lt;vector&lt;int&gt;&gt;&amp; points, int n) {<br \/>\n        pos.resize(n);<br \/>\n        for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n            pos[i].x &#061; points[i][0];<br \/>\n            pos[i].y &#061; points[i][1];<br \/>\n            pos[i].id &#061; i;<br \/>\n        }<br \/>\n        build(n);<br \/>\n        for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n            swap(pos[i].x, pos[i].y);<br \/>\n        }<br \/>\n        build(n);<br \/>\n        for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n            pos[i].x &#061; -pos[i].x;<br \/>\n        }<br \/>\n        build(n);<br \/>\n        for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n            swap(pos[i].x, pos[i].y);<br \/>\n        }<br \/>\n        build(n);<br \/>\n    }<\/p>\n<p>    int minCostConnectPoints(vector&lt;vector&lt;int&gt;&gt;&amp; points) {<br \/>\n        int n &#061; points.size();<br \/>\n        solve(points, n);<\/p>\n<p>        DisjointSetUnion dsu(n);<br \/>\n        sort(edges.begin(), edges.end());<br \/>\n        int ret &#061; 0, num &#061; 1;<br \/>\n        for (auto&amp; [len, x, y] : edges) {<br \/>\n            if (dsu.unionSet(x, y)) {<br \/>\n                ret &#043;&#061; len;<br \/>\n                num&#043;&#043;;<br \/>\n                if (num &#061;&#061; n) {<br \/>\n                    break;<br \/>\n                }<br \/>\n            }<br \/>\n        }<br \/>\n        return ret;<br \/>\n    }<br \/>\n};<\/p>\n<p>\u611f\u8c22\u5404\u4f4d\u9605\u8bfb\u5230\u6b64\u5904&#xff0c;\u6211\u4eec\u4e0d\u65e5\u76f8\u89c1\u3002<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb861\u6b21\uff0c\u70b9\u8d5e15\u6b21\uff0c\u6536\u85cf18\u6b21\u3002\u672c\u6587\u63a2\u8ba8\u4e86\u4f7f\u7528Kruskal\u7b97\u6cd5\u89e3\u51b3LeetCode 1584\u9898\uff08\u8fde\u63a5\u6240\u6709\u70b9\u7684\u6700\u5c0f\u8d39\u7528\uff09\u7684\u4f18\u5316\u65b9\u6cd5\u3002\u9488\u5bf9\u7a20\u5bc6\u56fe\u7684\u7279\u6027\uff0c\u6587\u7ae0\u63d0\u51fa\u901a\u8fc7\u51e0\u4f55\u5173\u7cfb\uff0845\u5ea6\u89d2\u5206\u5272\uff09\u5c06\u7a20\u5bc6\u56fe\u8f6c\u5316\u4e3a\u7a00\u758f\u56fe\uff0c\u4ece\u800c\u63d0\u5347Kruskal\u7b97\u6cd5\u6548\u7387\u3002\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5e76\u67e5\u96c6\u548c\u4e8c\u53c9\u7d22\u5f15\u6811\uff08BIT\uff09\u7684\u5b9e\u73b0\uff0c\u7528\u4e8e\u5224\u65ad\u6210\u73af\u548c\u5feb\u901f\u68c0\u7d22\u533a\u57df\u6700\u5c0f\u8fb9\u3002\u6700\u7ec8\u901a\u8fc7\u5750\u6807\u53d8\u6362\u5904\u7406\u56db\u4e2a\u8c61\u9650\uff0c\u751f\u6210\u5019\u9009\u8fb9\u96c6\u5408\uff0c\u5e76\u4f7f\u7528Kruskal\u7b97\u6cd5\u6784\u5efa\u6700\u5c0f\u751f\u6210\u6811\u3002\u8be5\u65b9\u6848\u5c06\u539f\u59cbO(n\u00b2)\u7684\u8fb9\u6570\u4f18\u5316\u4e3aO(n)\u7ea7\u522b\uff0c\u663e\u8457\u63d0\u9ad8\u4e86\u7b97\u6cd5\u6027\u80fd\u3002<\/p>\n","protected":false},"author":2,"featured_media":58075,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,2692,1813,427,925],"topic":[],"class_list":["post-58080","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-c","tag-leetcode","tag-1813","tag-427","tag-925"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u529b\u6263\u6bcf\u65e5\u4e00\u5237Day 8 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/58080.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u529b\u6263\u6bcf\u65e5\u4e00\u5237Day 8 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb861\u6b21\uff0c\u70b9\u8d5e15\u6b21\uff0c\u6536\u85cf18\u6b21\u3002\u672c\u6587\u63a2\u8ba8\u4e86\u4f7f\u7528Kruskal\u7b97\u6cd5\u89e3\u51b3LeetCode 1584\u9898\uff08\u8fde\u63a5\u6240\u6709\u70b9\u7684\u6700\u5c0f\u8d39\u7528\uff09\u7684\u4f18\u5316\u65b9\u6cd5\u3002\u9488\u5bf9\u7a20\u5bc6\u56fe\u7684\u7279\u6027\uff0c\u6587\u7ae0\u63d0\u51fa\u901a\u8fc7\u51e0\u4f55\u5173\u7cfb\uff0845\u5ea6\u89d2\u5206\u5272\uff09\u5c06\u7a20\u5bc6\u56fe\u8f6c\u5316\u4e3a\u7a00\u758f\u56fe\uff0c\u4ece\u800c\u63d0\u5347Kruskal\u7b97\u6cd5\u6548\u7387\u3002\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5e76\u67e5\u96c6\u548c\u4e8c\u53c9\u7d22\u5f15\u6811\uff08BIT\uff09\u7684\u5b9e\u73b0\uff0c\u7528\u4e8e\u5224\u65ad\u6210\u73af\u548c\u5feb\u901f\u68c0\u7d22\u533a\u57df\u6700\u5c0f\u8fb9\u3002\u6700\u7ec8\u901a\u8fc7\u5750\u6807\u53d8\u6362\u5904\u7406\u56db\u4e2a\u8c61\u9650\uff0c\u751f\u6210\u5019\u9009\u8fb9\u96c6\u5408\uff0c\u5e76\u4f7f\u7528Kruskal\u7b97\u6cd5\u6784\u5efa\u6700\u5c0f\u751f\u6210\u6811\u3002\u8be5\u65b9\u6848\u5c06\u539f\u59cbO(n\u00b2)\u7684\u8fb9\u6570\u4f18\u5316\u4e3aO(n)\u7ea7\u522b\uff0c\u663e\u8457\u63d0\u9ad8\u4e86\u7b97\u6cd5\u6027\u80fd\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/58080.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-15T18:00:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250815180030-689f75be8ef99.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"17 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/58080.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/58080.html\",\"name\":\"\u529b\u6263\u6bcf\u65e5\u4e00\u5237Day 8 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-08-15T18:00:37+00:00\",\"dateModified\":\"2025-08-15T18:00:37+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/58080.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/58080.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/58080.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u529b\u6263\u6bcf\u65e5\u4e00\u5237Day 8\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u529b\u6263\u6bcf\u65e5\u4e00\u5237Day 8 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/58080.html","og_locale":"zh_CN","og_type":"article","og_title":"\u529b\u6263\u6bcf\u65e5\u4e00\u5237Day 8 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb861\u6b21\uff0c\u70b9\u8d5e15\u6b21\uff0c\u6536\u85cf18\u6b21\u3002\u672c\u6587\u63a2\u8ba8\u4e86\u4f7f\u7528Kruskal\u7b97\u6cd5\u89e3\u51b3LeetCode 1584\u9898\uff08\u8fde\u63a5\u6240\u6709\u70b9\u7684\u6700\u5c0f\u8d39\u7528\uff09\u7684\u4f18\u5316\u65b9\u6cd5\u3002\u9488\u5bf9\u7a20\u5bc6\u56fe\u7684\u7279\u6027\uff0c\u6587\u7ae0\u63d0\u51fa\u901a\u8fc7\u51e0\u4f55\u5173\u7cfb\uff0845\u5ea6\u89d2\u5206\u5272\uff09\u5c06\u7a20\u5bc6\u56fe\u8f6c\u5316\u4e3a\u7a00\u758f\u56fe\uff0c\u4ece\u800c\u63d0\u5347Kruskal\u7b97\u6cd5\u6548\u7387\u3002\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5e76\u67e5\u96c6\u548c\u4e8c\u53c9\u7d22\u5f15\u6811\uff08BIT\uff09\u7684\u5b9e\u73b0\uff0c\u7528\u4e8e\u5224\u65ad\u6210\u73af\u548c\u5feb\u901f\u68c0\u7d22\u533a\u57df\u6700\u5c0f\u8fb9\u3002\u6700\u7ec8\u901a\u8fc7\u5750\u6807\u53d8\u6362\u5904\u7406\u56db\u4e2a\u8c61\u9650\uff0c\u751f\u6210\u5019\u9009\u8fb9\u96c6\u5408\uff0c\u5e76\u4f7f\u7528Kruskal\u7b97\u6cd5\u6784\u5efa\u6700\u5c0f\u751f\u6210\u6811\u3002\u8be5\u65b9\u6848\u5c06\u539f\u59cbO(n\u00b2)\u7684\u8fb9\u6570\u4f18\u5316\u4e3aO(n)\u7ea7\u522b\uff0c\u663e\u8457\u63d0\u9ad8\u4e86\u7b97\u6cd5\u6027\u80fd\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/58080.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-08-15T18:00:37+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250815180030-689f75be8ef99.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"17 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/58080.html","url":"https:\/\/www.wsisp.com\/helps\/58080.html","name":"\u529b\u6263\u6bcf\u65e5\u4e00\u5237Day 8 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-08-15T18:00:37+00:00","dateModified":"2025-08-15T18:00:37+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/58080.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/58080.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/58080.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u529b\u6263\u6bcf\u65e5\u4e00\u5237Day 8"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/58080","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=58080"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/58080\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/58075"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=58080"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=58080"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=58080"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=58080"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}