{"id":376,"date":"2026-03-24T19:51:31","date_gmt":"2026-03-24T11:51:31","guid":{"rendered":"https:\/\/jiangqvweihuan.cn\/?p=376"},"modified":"2026-03-30T18:37:37","modified_gmt":"2026-03-30T10:37:37","slug":"%e9%80%86%e5%ba%8f%e5%af%b9","status":"publish","type":"post","link":"https:\/\/jiangqvweihuan.cn\/index.php\/2026\/03\/24\/%e9%80%86%e5%ba%8f%e5%af%b9\/","title":{"rendered":"\u7b97\u6cd5\u5fc3\u4f20\u00b7\u9006\u5e8f\u5bf9"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u5f15\u5165<\/h2>\n\n\n\n<p>\u6211\u4eec\u601d\u8003\u8fd9\u6837\u4e00\u4e2a\u95ee\u9898\uff1a<\/p>\n\n\n<p>\u5bf9\u4e8e\u7ed9\u5b9a\u7684\u4e00\u6bb5\u6b63\u6574\u6570\u5e8f\u5217\uff0c\u9006\u5e8f\u5bf9\u5c31\u662f\u5e8f\u5217\u4e2d ai > aj\u4e14 i < j \u7684\u6709\u5e8f\u5bf9\u3002\n\u8f93\u5165\u8bf4\u660e\n\u7b2c\u4e00\u884c\uff0c\u4e00\u4e2a\u6570 n\uff0c\u8868\u793a\u5e8f\u5217\u4e2d\u6709 n \u4e2a\u6570\u3002\n\u7b2c\u4e8c\u884c n \u4e2a\u6570\uff0c\u8868\u793a\u7ed9\u5b9a\u7684\u5e8f\u5217\u3002\u5e8f\u5217\u4e2d\u6bcf\u4e2a\u6570\u5b57\u4e0d\u8d85\u8fc7 10^9\u3002\n\u8f93\u51fa\u8bf4\u660e\n\u8f93\u51fa\u5e8f\u5217\u4e2d\u9006\u5e8f\u5bf9\u7684\u6570\u76ee\u3002\n\u8f93\u5165\u6837\u4f8b\n6\n5 4 2 6 3 1\n\u8f93\u51fa\u6837\u4f8b\n11\n\n<\/p>\n\n\n\n<p>\u4e0d\u96be\u53d1\u73b0\uff0c\u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u6570\u5982\u679c\u6211\u4eec\u60f3\u8981\u66b4\u529b\u53bb\u904d\u5386\u6bcf\u4e00\u4e2a\u7684\u6570\u7684\u9006\u5e8f\u5bf9\u6570\uff0c\u663e\u7136\u65f6\u95f4\u590d\u6742\u5ea6\u662fO(n^2)\uff0c\u6211\u4eec\u8981\u627e\u4e00\u4e2a\u66f4\u52a0\u9ad8\u6548\u7684\u65b9\u6cd5\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u4e0d\u59a8\u5c06\u76ee\u5149\u653e\u5230\u5f52\u5e76\u6392\u5e8f\u4e0a\uff0c\u6240\u8c13\u7684\u5f52\u5e76\u6392\u5e8f\u4e5f\u662f\u6392\u5e8f\u7684\u4e00\u79cd\uff0c\u50cf\u5192\u6ce1\u6392\u5e8f\u548c\u5feb\u901f\u6392\u5e8f\u90fd\u662f\u6211\u4eec\u7684\u8001\u670b\u53cb\u4e86\uff0c\u800c\u5bf9\u4e8e\u5f52\u5e76\u6392\u5e8f\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e0a\u548c\u5feb\u901f\u6392\u5e8f\u4e00\u81f4\uff0c\u4e0d\u540c\u7684\u662f\u5b83\u5b9e\u73b0\u7684\u8fc7\u7a0b\u662f\u7a33\u5b9a\u7684\uff0c\u4e0b\u9762\u6211\u5c31\u8fd9\u4e00\u4e2a\u6837\u4f8b\u7528\u9012\u5f52\u65b9\u6cd5\u5f52\u5e76\u6392\u5e8f\u5b9e\u73b0\u4ee5\u4e0b\u8fc7\u7a0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/jiangqvweihuan.cn\/wp-content\/uploads\/2026\/03\/image-6-1024x780.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"780\" data-original=\"https:\/\/jiangqvweihuan.cn\/wp-content\/uploads\/2026\/03\/image-6-1024x780.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-384\" style=\"width:579px;height:auto\"  sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/div><\/figure>\n\n\n\n<p>\u4f46\u662f\u8fd9\u548c\u6211\u4eec\u8981\u6c42\u7684\u9006\u5e8f\u5bf9\u6709\u4ec0\u4e48\u5173\u7cfb\u5462\uff1f<\/p>\n\n\n\n<p>\u4e0d\u59a8\u518d\u4ed4\u7ec6\u601d\u8003\u4e00\u4e0b\u5f52\u5e76\u6392\u5e8f\u7684\u8fc7\u7a0b\uff0c\u4e3a\u4e86\u5f97\u5230\u6700\u540e\u7684\u7a33\u5b9a\u6709\u5e8f\u7684\u5e8f\u5217\uff0c\u6211\u4eec\u5c06\u6bcf\u4e00\u90e8\u5206\u90fd\u6309\u533a\u5757\u8fdb\u884c\u4e86\u6392\u5e8f\uff0c\u6700\u540e\u5408\u5e76\uff0c\u4e00\u76f4\u91cd\u590d\u8fd9\u4e00\u4e2a\u8fc7\u7a0b\u3002\u90a3\u9006\u5e8f\u5bf9\u7684\u7279\u5f81\u53c8\u662f\u4ec0\u4e48\u5462\uff1f\u6570\u51fa\u73b0\u5728\u6392\u5e8f\u540e\u672c\u8be5\u51fa\u73b0\u4e4b\u524d\u7684\u4f4d\u7f6e\u7684\u503c\uff0c\u90a3\u4e48\u6211\u4eec\u53ef\u4ee5\u5728\u5f52\u5e76\u6392\u5e8f\u7684\u8fc7\u7a0b\u4e2d\u7edf\u8ba1\u9006\u5e8f\u5bf9\u7684\u6570\u91cf\uff0c\u7531\u4e8e\u5f52\u5e76\u6392\u5e8f\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662fO(n*log n),\u56e0\u6b64\u4e0d\u4f1a\u8d85\u65f6\uff0c\u4e0b\u9762\u7ed9\u51fa\u5b9e\u73b0\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;bits\/stdc++.h&gt;\nusing namespace std;\n\nconst int N = 500005;\nint a&#91;N];\nint h&#91;N];\nlong long ans = 0;\n\n\/\/\u6a21\u62df\u5408\u5e76\nvoid merge(int l, int r, int mid)\n{\n    int pos = l;\n    int i = l;\n    int j = mid + 1;\n    while (i &lt;= mid &amp;&amp; j &lt;= r)\n    {\n        if (a&#91;i] &gt; a&#91;j])\n        {\n            h&#91;pos++] = a&#91;j++];\n            \/\/ \u5f53\u51fa\u73b0\u53f3\u5e8f\u5217\u7684\u6570\u6bd4\u5de6\u5e8f\u5217\u7684\u8fd8\u5c0f\u65f6\uff0c\u4ee3\u8868\u7740\u8fd9\u65f6\u5019\u7684\u5de6\u5e8f\u5217\u6240\u6709\u6570\u90fd\u662f\u8fd9\u4e2a\u6570\u7684\u9006\u5e8f\u5bf9\n            ans += (mid - i + 1);\n        }\n        else\n        {\n            h&#91;pos++] = a&#91;i++];\n        }\n    }\n    while (i &lt;= mid)\n        h&#91;pos++] = a&#91;i++];\n    while (j &lt;= r)\n        h&#91;pos++] = a&#91;j++];\n    for (int k = l; k &lt;= r; ++k)\n    {\n        a&#91;k] = h&#91;k];\n    }\n}\n\n\/\/\u6a21\u62df\u5206\u7ec4(\u9012\u5f52)\nvoid f(int l, int r)\n{\n    int mid = l + ((r - l) &gt;&gt; 1);\n    if (l == r)\n        return;\n    f(l, mid);\n    f(mid + 1, r);\n    merge(l, r, mid);\n}\n\nsigned main()\n{\n    int n;\n    cin &gt;&gt; n;\n    for (int i = 1; i &lt;= n; ++i)\n    {\n        cin &gt;&gt; a&#91;i];\n    }\n    f(1, n);\n    cout &lt;&lt; ans;\n}<\/code><\/pre>\n\n\n\n<p>\u76f8\u4fe1\u81ea\u5df1\u63a8\u6f14\u51e0\u904d\u4ee3\u7801\u4e4b\u540e\u8bfb\u8005\u5c31\u4f1a\u53d1\u73b0\u5f52\u5e76\u6392\u5e8f\u5728\u5904\u7406\u9006\u5e8f\u5bf9\u95ee\u9898\u4e0a\u7684\u5999\u5904\u3002<\/p>\n\n\n\n<p>\u9006\u5e8f\u5bf9\u7684\u5f52\u5e76\u6392\u5e8f\u8fd8\u6709\u53e6\u4e00\u79cd\u7684\u8868\u793a\u65b9\u5f0f\uff0c\u8fed\u4ee3\u5f52\u5e76\u6392\u5e8f\uff0c\u7531\u4e8e\u4e00\u822c\u60c5\u51b5\u8fed\u4ee3\u5f52\u5e76\u6392\u5e8f\u5df2\u7ecf\u8db3\u4ee5\u89e3\u51b3\u7ade\u8d5b\u4e2d\u78b0\u89c1\u7684\u95ee\u9898\uff0c\u56e0\u6b64\u8fed\u4ee3\u5f52\u5e76\u6392\u5e8f\u6c42\u9006\u5e8f\u5bf9\u8fd9\u91cc\u6211\u4ec5\u4ec5\u7ed9\u51fa\u4ee3\u7801\uff0c\u4f9b\u5927\u5bb6\u5b66\u4e60\u53c2\u8003\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;bits\/stdc++.h&gt;\nusing namespace std;\n\nconst int N = 500005;\nint a&#91;N], tmp&#91;N];\nlong long ans = 0;\n\nvoid merge(int l, int mid, int r)\n{\n    int i = l, j = mid + 1, k = l;\n    while (i &lt;= mid &amp;&amp; j &lt;= r)\n    {\n        if (a&#91;i] &gt; a&#91;j])\n        {\n            tmp&#91;k++] = a&#91;j++];\n            ans += (mid - i + 1);\n        }\n        else\n        {\n            tmp&#91;k++] = a&#91;i++];\n        }\n    }\n    while (i &lt;= mid)\n        tmp&#91;k++] = a&#91;i++];\n    while (j &lt;= r)\n        tmp&#91;k++] = a&#91;j++];\n    for (int p = l; p &lt;= r; ++p)\n        a&#91;p] = tmp&#91;p];\n}\n\nint main()\n{\n    int n;\n    cin &gt;&gt; n;\n    for (int i = 1; i &lt;= n; ++i)\n        cin &gt;&gt; a&#91;i];\n\n    \/\/ \u81ea\u5e95\u5411\u4e0a\u5f52\u5e76\n    \/\/ len &lt;&lt;= 1 \u7b49\u4ef7\u4e8elen *= 2\uff0c\u53ea\u4e0d\u8fc7\u524d\u8005\u662f\u4f4d\u8fd0\u7b97\u6548\u7387\u66f4\u9ad8\n    for (int len = 1; len &lt; n; len &lt;&lt;= 1)\n    {\n        for (int l = 1; l + len &lt;= n; l += (len &lt;&lt; 1))\n        {\n            int mid = l + len - 1;\n            int r = min(l + (len &lt;&lt; 1) - 1, n);\n            merge(l, mid, r);\n        }\n    }\n\n    cout &lt;&lt; ans;\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p>\u901a\u8fc7\u8fed\u4ee3\u7684\u65b9\u6cd5\uff0c\u6211\u4eec\u5bb9\u6613\u5370\u8bc1\u51fa\u4e4b\u524d\u6211\u7ed9\u51fa\u7684\u5f52\u5e76\u6392\u5e8f\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662fO(n * log n)\u3002<\/p>\n\n\n\n<p>\u5176\u5b9e\u5bf9\u4e8e\u8fd9\u4e00\u7ae0\u6807\u9898\u5728\u6211\u7684\u7b97\u6cd5\u7f16\u7a0b\u8def\u91cc\u9762\u7684\u4f4d\u7f6e\u5341\u5206\u7684\u4e0d\u9002\u5408\uff0c\u9996\u5148\u662f\u9006\u5e8f\u5bf9\u5e76\u4e0d\u662f\u4e00\u4e2a\u5e38\u7528\u7684\u7b97\u6cd5\u6a21\u677f\uff0c\u540c\u65f6\u5f52\u5e76\u6392\u5e8f\u53c8\u4e0d\u53ea\u9650\u4e8e\u89e3\u51b3\u9006\u5e8f\u5bf9\u7684\u95ee\u9898\uff0c\u56e0\u6b64\u8fd9\u4e00\u7ae0\u53ef\u80fd\u6709\u4e00\u4e9b\u7a81\u5140\uff0c\u5c31\u5f53\u4f5c\u4e00\u7bc7\u4e60\u9898\u7ae0\u8282\u5b66\u4e60\u9006\u5e8f\u5bf9\u8fd9\u4e13\u95e8\u7684\u4e00\u4e2a\u8f83\u4e3a\u72ec\u7acb\u7684\u9898\u578b\u548c\u521d\u6b65\u4e86\u89e3\u5f52\u5e76\u6392\u5e8f\u5427\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u7ecf\u5178\u4f8b\u9898<\/h2>\n\n\n\n<p><a href=\"https:\/\/www.luogu.com.cn\/problem\/P1908\">P1908 \u9006\u5e8f\u5bf9 &#8211; \u6d1b\u8c37<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/www.nowcoder.com\/practice\/96bd6684e04a44eb80e6a68efc0ec6c5\">\u6570\u7ec4\u4e2d\u7684\u9006\u5e8f\u5bf9_\u725b\u5ba2\u9898\u9738_\u725b\u5ba2\u7f51<\/a><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u5f15\u5165 \u6211\u4eec\u601d\u8003\u8fd9\u6837\u4e00\u4e2a\u95ee\u9898\uff1a \u4e0d\u96be\u53d1\u73b0\uff0c\u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u6570\u5982\u679c\u6211\u4eec\u60f3\u8981\u66b4\u529b\u53bb\u904d\u5386\u6bcf\u4e00\u4e2a\u7684\u6570\u7684\u9006\u5e8f\u5bf9\u6570\uff0c\u663e\u7136\u65f6\u95f4\u590d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":156,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,15,12],"tags":[],"class_list":["post-376","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-article","category-algorithm-template","category-programming-algorithm-road"],"_links":{"self":[{"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/posts\/376","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/comments?post=376"}],"version-history":[{"count":5,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/posts\/376\/revisions"}],"predecessor-version":[{"id":393,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/posts\/376\/revisions\/393"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/media\/156"}],"wp:attachment":[{"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/media?parent=376"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/categories?post=376"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/tags?post=376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}