{"id":1750,"date":"2021-08-28T20:06:08","date_gmt":"2021-08-28T12:06:08","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=1750"},"modified":"2021-08-29T20:46:48","modified_gmt":"2021-08-29T12:46:48","slug":"codeforces-round-740","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/codeforces-round-740\/","title":{"rendered":"Codeforces Round #740"},"content":{"rendered":"<h1><span class=\"ez-toc-section\" id=\"%E4%BC%A0%E9%80%81%E9%97%A8\"><\/span>\u4f20\u9001\u95e8<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p><a href=\"https:\/\/codeforces.com\/contest\/1558\">https:\/\/codeforces.com\/contest\/1558<\/a><\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_65 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69f153304508a\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69f153304508a\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.shuizilong.com\/house\/archives\/codeforces-round-740\/#%E4%BC%A0%E9%80%81%E9%97%A8\" title=\"\u4f20\u9001\u95e8\">\u4f20\u9001\u95e8<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.shuizilong.com\/house\/archives\/codeforces-round-740\/#Problem_B_Up_the_Strip\" title=\"Problem B. Up the Strip\">Problem B. Up the Strip<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.shuizilong.com\/house\/archives\/codeforces-round-740\/#Problem_C_Bottom-Tier_Reversals\" title=\"Problem C. Bottom-Tier Reversals\">Problem C. Bottom-Tier Reversals<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.shuizilong.com\/house\/archives\/codeforces-round-740\/#Problem_D_Top-Notch_Insertions\" title=\"Problem D. Top-Notch Insertions\">Problem D. Top-Notch Insertions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.shuizilong.com\/house\/archives\/codeforces-round-740\/#Problem_E_Down_Below\" title=\"Problem E. Down Below\">Problem E. Down Below<\/a><\/li><\/ul><\/nav><\/div>\n\n<p>\u4e45\u8fdd\u7684 Tourist round&#8230;<br \/>\n\u56e0\u4e3a B \u9898\u6ca1\u505a\u51fa\u6765\uff0c\u76f4\u63a5\u53c8\u8dcc\u6210\u84dd\u540d\u3002\u3002\u3002<\/p>\n<h1><span class=\"ez-toc-section\" id=\"Problem_B_Up_the_Strip\"><\/span>Problem B. Up the Strip<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>\u7ed9\u5b9a\u4e0b\u9762\u7684\u9012\u63a8\u516c\u5f0f\uff1a<br \/>\n$f(x) = \\sum \\limits_{y=1}^{x-1} f(x-y) + \\sum \\limits_{z=2}^{x} f(\\lfloor \\frac{x}{z} \\rfloor)$<br \/>\nf(1) = 1\uff0c\u6c42 f(n)\u3002<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\nconst int N = int(4e6) + 9;\r\n\r\nInt f&#x5B;N], s&#x5B;N];\r\nint n;\r\n\r\nint main()\r\n{\r\n\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n    \/\/freopen(&quot;\/Users\/minakokojima\/Documents\/GitHub\/ACM-Training\/Workspace\/out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n\r\n    RD(n, MOD); f&#x5B;n] = s&#x5B;n] = 1;\r\n    DWN(i, n, 1) {\r\n        f&#x5B;i] = s&#x5B;i+1];\r\n        \/\/FOR_1(j, 2, i) f&#x5B;i\/j] += f&#x5B;i];\r\n        for (int j=2;i*j&lt;=n;++j) {\r\n            int l = i*j, r = min(n+1, l+j);\r\n            f&#x5B;i] += s&#x5B;l]-s&#x5B;r];\r\n        }\r\n        s&#x5B;i] = s&#x5B;i+1] + f&#x5B;i];\r\n    }\r\n\r\n    cout &lt;&lt; f&#x5B;1] &lt;&lt; endl;\r\n}\r\n<\/pre>\n<p>\u975e\u5e38 nice \u7684\u9898\u3002\u3002\u4e2a\u4eba\u975e\u5e38\u559c\u6b22\u3002\u3002\u3002naive \u7684\u6211\u53ea\u4f1a\u7c7b\u4f3c\u6570\u8bba\u5206\u5757\u7684 sqrt \u641e\u6cd5\u3002<br \/>\n\u4f46\u8fd9\u4e2a\u65b9\u6cd5\u53ea\u80fd\u8fc7 div2 \u7684\u5f31\u5316\u7248\uff0c\u6bd4\u8d5b\u65f6\u534e\u4e3d\u7684 TLE \u4e86\u3002<br \/>\n\u6b63\u786e\u7684\u505a\u6cd5\u662f\u8003\u5bdf\u76f8\u90bb\u72b6\u6001\u6c42\u548c\u8fc7\u7a0b\u4e2d\u7684 diff\uff0c\u7136\u540e\u6574\u5757\u6574\u5757\u7684\u5904\u7406\u3002\u3002<\/p>\n<h1><span class=\"ez-toc-section\" id=\"Problem_C_Bottom-Tier_Reversals\"><\/span>Problem C. Bottom-Tier Reversals<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u6392\u5217\uff0c\u6bcf\u6b21\u4f60\u53ef\u4ee5\u9009\u4e00\u4e2a\u524d\u7f00\u7ffb\u8f6c\uff0c\u95ee\u662f\u5426\u80fd\u5728 5n\/2 \u6b65\u6570\u5185\u6392\u5e8f\u8fd9\u4e2a\u6392\u5217\u3002<br \/>\n\u9012\u5f52\u6784\u9020\uff0c\u5206\u60c5\u51b5\u5012\u7740\u8ba8\u8bba\u5373\u53ef\uff0c\u53d1\u73b0\u6070\u597d\u81f3\u591a 5 \u6b65\u53ef\u4ee5\u5c06\u89c4\u6a21\u51cf\u5c0f 2\uff0c\u6ee1\u8db3\u6761\u4ef6\u3002<\/p>\n<h1><span class=\"ez-toc-section\" id=\"Problem_D_Top-Notch_Insertions\"><\/span>Problem D. Top-Notch Insertions<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>\u8ba1\u6570\u3002\u95ee\u6709\u591a\u5c11\u957f\u5ea6\u4e3a n \u7684\u6392\u5217 ai\uff0c\u6ee1\u8db3 ai \u7684\u503c\u57df\u4e3a [1,n] \u4e14\uff0c\u5bf9\u5b83\u6267\u884c\u63d2\u5165\u6392\u5e8f\u65f6\uff0c\u63d2\u5165\u7684\u65f6\u523b\u548c\u4f4d\u7f6e\u6070\u597d\u65f6\u7ed9\u5b9a\u7684 m \u4e2a\u64cd\u4f5c\u3002<\/p>\n<p>\u5047\u8bbe\u4e0d\u63d0\u4f9b\u4efb\u4f55\u63d2\u5165\u4fe1\u606f\uff0c\u90a3\u4e48\u4efb\u610f\u6784\u9020\u4e00\u4e2a\u957f\u5ea6\u4e3a n\uff0c\u503c\u57df\u4e3a [1, n] \u7684\u975e\u4e25\u683c\u5355\u8c03\u9012\u589e\u5e8f\u5217\u90fd\u6ee1\u8db3\u6761\u4ef6\uff0c\u65b9\u6848\u6570\u662f\u7ecf\u5178\u7684 C(2n+1,n)\u3002<br \/>\n\uff08\u8bc1\u660e\uff0c\u540e\u9762\u7684\u6bcf\u4e2a\u6570\u90fd\u591a\u4e00\u4e2a\u7b49\u53f7\u6210\u7acb\u7684\u5f71\u5b50\u72b6\u6001\uff0c\u76f8\u5f53\u4e8e\u7ed9\u540e\u9762\u6bcf\u4e2a\u4f4d\u7f6e\u90fd\u7d2f\u52a0 1\uff0c\u4ee5\u4fdd\u8bc1\u6bcf\u4e2a\u6570\u4e0d\u76f8\u7b49\uff0c\u6784\u9020\u51fa\u4ece 2n+1 \u4e2a\u6570\u91cc\u9009 n \u4e2a\u6570\u7684\u4e00\u4e00\u6620\u5c04\u3002\uff09<br \/>\n\u90a3\u4e48\u5982\u679c\u51fa\u73b0\u4e86\u63d2\u5165\u4fe1\u606f\uff0c\u4f1a\u8ba9\u4e00\u4e9b\u4f4d\u7f6e\u7684\u7b49\u53f7\u5173\u7cfb\u4e0d\u6210\u7acb\uff0c\u4ece\u800c\u4e0a\u9762\u7684\u5f71\u5b50\u72b6\u6001\u53d8\u5c11\uff0c\u5047\u8bbe\u6709 m \u4e2a\u7b49\u53f7\u4e0d\u6210\u7acb\uff0c\u7b54\u6848\u5c31\u662f C(2n+1-m,n)\u3002<\/p>\n<p>\u4f46\u662f\u63d0\u4f9b\u7684\u63d2\u5165\u4fe1\u606f\u4e0d\u4e00\u5b9a\u4e00\u5b9a\u4f1a\u8ba9 m+=1\uff0c\u6709\u4e9b\u4fe1\u606f\u662f\u4f1a\u91cd\u590d\u7684\u3002<br \/>\n\u95ee\u9898\u53d8\u4e3a\u4f7f\u7528\u6570\u636e\u7ed3\u6784\u7ef4\u62a4\u51fa\u7b49\u53f7\u4e0d\u6210\u7acb\u7684\u4f4d\u7f6e\u5373\u53ef\u3002<\/p>\n<p>\u6807\u51c6\u505a\u6cd5\u662f Treap \u6216\u8005 Splay \u8fd9\u79cd\uff0c\u53ef\u4ee5\u652f\u6301\u5728 kth \u4f4d\u7f6e\u63d2\u5165\u4e00\u4e2a\u6570\u7684\u5e73\u8861\u6811\u7ed3\u6784\uff0c\u6ce8\u610f\u9700\u8981\u52a8\u6001\u79bb\u6563\u5316\u3002\u590d\u6742\u5ea6 O(nlogn)\u3002<br \/>\n<a href=\"https:\/\/codeforces.com\/contest\/1558\/submission\/127258945\">Splay + \u52a8\u6001\u79bb\u6563\u5316\uff08608ms\uff09<\/a><\/p>\n<p>\u5f53\u7136\u4e5f\u53ef\u4ee5\u4f7f\u7528 rope \u5361\u8fc7\u53bb\uff0c\u590d\u6742\u5ea6 O(nsqrt(n))\uff0c\u4f7f\u7528 rope \u7684\u4ee3\u7801\u975e\u5e38\u4e4b\u77ed\uff0c\u5c31\u51e0\u884c\uff0c\u800c\u4e14\u4f3c\u4e4e\u56e0\u4e3a\u662f\u5947\u5999\u7684\u53ef\u6301\u4e45\u5316\u5757\u72b6\u94fe\u8868\u7ed3\u6784\uff0c\u751a\u81f3\u4e0d\u9700\u8981\u52a8\u6001\u79bb\u6563\u5316\uff0c<br \/>\n\u867d\u7136 <a href=\"https:\/\/t.me\/algorithm_daily_of_minako\/1774\">\u4f7f\u7528 rope \u6709\u53ef\u80fd\u4f1a\u5e26\u6765\u4e0d\u5e78<\/a>\uff0c\u4f46\u662f\u54ea\u6015\u662f\u7528\u6765\u5bf9\u62cd\u4e5f\u6bd4\u66b4\u529b\u8981\u597d\u5199\u7684\u591a\u3002\u3002\u3002<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n    Rush {\r\n        r = r0; RD(n); int m = 0; Rush {\r\n            int x, y; RD(x, y);\r\n            if (r&#x5B;y] == 0) {\r\n                ++m;\r\n                r.insert(y+1, 1);\r\n            } else {\r\n                r.insert(y, 0);\r\n            }\r\n            \/\/REP(i, 10) cout &lt;&lt; r&#x5B;i]; cout &lt;&lt;endl;\r\n        }\r\n        cout &lt;&lt; Binom(n+n-1-m, n) &lt;&lt; endl;\r\n    }\r\n<\/pre>\n<p><a href=\"https:\/\/codeforces.com\/contest\/1558\/submission\/127228928\">Rope\uff081965ms\uff09<\/a><\/p>\n<p>\u8c8c\u4f3c\u8fd8\u6709\u4e00\u79cd\u505a\u6cd5\u662f\u5012\u7740\u505a\uff0c\u6b64\u65f6\u6bcf\u6b21\u63d2\u5165\u7684\u4f4d\u7f6e\u5c31\u662f\u6700\u7ec8\u7684\u4f4d\u7f6e\uff0c\u4e8e\u662f\u53ef\u4ee5 \u6811\u72b6\u6570\u7ec4 \u8bb0\u5f55 Offset + \u4e8c\u5206\u7b54\u6848\u6c42 kth\uff0c\u590d\u6742\u5ea6 O(nlog2n)\uff0c\u5b9e\u9645\u8dd1\u5f97\u6bd4\u5e73\u8861\u6811\u8981\u5feb\u3002<br \/>\n<a href=\"https:\/\/codeforces.com\/contest\/1558\/submission\/127326711\">\u6811\u72b6\u6570\u7ec4(374ms)<\/a><\/p>\n<h1><span class=\"ez-toc-section\" id=\"Problem_E_Down_Below\"><\/span>Problem E. Down Below<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>\u56fe\u8bba\u9898\u3002\u7ed9\u5b9a\u4e00\u4e2a n \u4e2a\u70b9 m \u6761\u8fb9\u7684\u65e0\u5411\u56fe\u3002\uff08\u65e0\u91cd\u8fb9\u3001\u65e0\u81ea\u73af\u3001\u8054\u901a\uff09<br \/>\n\u4f60\u4ece 1 \u51fa\u53d1\uff0c\u6bcf\u4e2a\u5176\u4ed6\u70b9\u90fd\u6709\u4e00\u4e2a\u602a\u7269\uff0c\u602a\u7269\u6709\u6570\u503c ai \u548c bi\uff0c\u5f53\u4f60\u5230\u8fbe i \u70b9\u65f6\uff0c\u4f60\u82f1\u96c4\u7684 power \u5fc5\u987b\u8981 > ai\uff0c\u602a\u7269\u88ab\u6d88\u706d\uff0c\u7136\u540e power += bi\u3002<br \/>\n\u4f60\u4e0d\u53ef\u4ee5\u91cd\u590d\u4f7f\u7528\u4e00\u6761\u8fb9\u3002\uff08\u8bbf\u95ee\u540e\u7acb\u523b\u8fd4\u56de\uff09<br \/>\n\u95ee\u8981\u6d88\u706d\u6240\u6709\u7684\u602a\u7269\uff0c\u82f1\u96c4\u51fa\u53d1\u65f6\u6240\u9700\u7684\u6700\u5c11 power \u65f6\u591a\u5c11\u3002<br \/>\nn &lt;= 1000, m &lt;= 2000<\/p>\n<p>\u5f00\u59cb\u4ee5\u4e3a\u662f\u53cc\u8fde\u901a\u5206\u91cf + \u6811 dp\u3002\u3002\u3002\u4f46\u662f\u5176\u5b9e\u53ef\u4ee5\u76f4\u63a5\u4e8c\u5206\u7b54\u6848\uff0c\u7136\u540e\u8fed\u4ee3\uff0c\u6bcf\u6b21\u7528 bfs() \u627e\u73af\u5373\u53ef\u3002<br \/>\n\u6bcf\u627e\u5230\u4e00\u4e2a\u73af\u5c31\u628a\u73af\u4e0a\u7684\u70b9\u5168\u52a0\u5230\u53ef\u8bbf\u95ee\u96c6\u5408\u91cc\u3002\u6211\u4eec\u751a\u81f3\u4e0d\u9700\u8981\u7ef4\u62a4\u8bbf\u95ee\u5230\u6bcf\u4e2a\u70b9\u65f6\u7684\u6700\u5927 power\uff0c\u56e0\u4e3a\u5982\u679c\u9700\u8981 relax&#8230; \u8bf4\u660e\u5df2\u7ecf\u51fa\u73b0\u73af\u4e86\u3002<br \/>\n\u903b\u8f91\u4e0a\u8fd9\u4e2a\u53ef\u8bbf\u95ee\u7684\u96c6\u5408\u5b9e\u9645\u4e0a\u53ef\u4ee5\u770b\u4f5c\u662f\u88ab\u5e76\u67e5\u96c6\u5408\u5e76\u5728\u4e00\u8d77\u5f62\u6210\u7684\u4e00\u4e2a super node\uff0c\u5b9e\u73b0\u4e0a\u8981\u8ba8\u8bba\u4e00\u4e0b\u627e\u5230\u7684\u73af\u662f\u5728\u5916\u90e8\uff0c\u8fd8\u662f\u9996\u4f4d\u90fd\u662f\u8fd9\u4e2a super node\uff0c\u867d\u7136\u903b\u8f91\u5f88\u7b80\u5355\uff0c\u4f46\u6bd4\u8f83\u5bb9\u6613\u5199\u75b5\u3002<\/p>\n<p><a href=\"https:\/\/codeforces.com\/contest\/1558\/submission\/127227578\">BFS \u627e\u73af<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f20\u9001\u95e8 https:\/\/codeforces.com\/contest\/1558 \u4e45\u8fdd\u7684 Tourist round&#8230; \u56e0\u4e3a B \u9898\u6ca1\u505a\u51fa\u6765\uff0c\u76f4\u63a5\u53c8\u8dcc\u6210\u84dd\u540d\u3002\u3002\u3002 Problem B. Up the Strip \u7ed9\u5b9a\u4e0b\u9762\u7684\u9012\u63a8\u516c\u5f0f\uff1a $f(x) = \\sum \\limits_{y=1}^{x-1} f(x-y) + \\sum \\limits_{z=2}^{x} f(\\lfloor \\frac{x}{z} \\rfloor)$ f(1) = 1\uff0c\u6c42 f(n)\u3002 const int N = int(4e6) + 9; Int f&#x5B;N], s&#x5B;N]; int n; int main() { #ifndef ONLINE_JUDGE freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin); \/\/freopen(&quot;\/Users\/minakokojima\/Documents\/GitHub\/ACM-Training\/Workspace\/out.txt&quot;, &quot;w&quot;, stdout); #endif RD(n, MOD); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[],"class_list":["post-1750","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-se","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1750","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/comments?post=1750"}],"version-history":[{"count":1,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1750\/revisions"}],"predecessor-version":[{"id":1753,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1750\/revisions\/1753"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=1750"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=1750"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=1750"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}