{"id":49,"date":"2011-09-16T05:00:12","date_gmt":"2011-09-15T21:00:12","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=49"},"modified":"2012-03-03T05:00:57","modified_gmt":"2012-03-02T21:00:57","slug":"codeforces-beta-round-87","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/codeforces-beta-round-87\/","title":{"rendered":"Codeforces Beta Round #87.. ."},"content":{"rendered":"<p>\uff08\u5728\u7f51\u5427\u505a CF \u7684\u5bc2\u5bde\u4f60\u4eec\u4e0d\u61c2\uff01\uff01\uff01\uff09<\/p>\n<p><a href=\"http:\/\/www.codeforces.com\/contest\/115\/room\/1\">\u8fd9\u76d8<\/a>\u662f TC \u9898\u5988 <a href=\"http:\/\/www.codeforces.com\/profile\/dolphinigle\">dolphinigle<\/a> \u7684\u573a\u3002\u3002<\/p>\n<p>A \u5f00\u59cb\u6ca1\u6709\u6ce8\u610f p[i] > i \u7684\u60c5\u51b5\u3002\u3002\u803d\u6401\u4e86\u4e00\u4e9b\u65f6\u95f4\u5728\u8c03\u8bd5\u4e0a\u3002<br \/>\nB \u7565\u3002\u3002<\/p>\n<p>\u4e4b\u540e\u5148\u8bfb\u4e86 D\uff0c\u662f\u4e00\u4e2a\u7ed9\u5b9a\u4e00\u4e2a\u8868\u8fbe\u5f0f\uff0c\u95ee\u52a0\u62ec\u53f7\u6570\u76ee\u7684\u9898\u76ee\uff0c<br \/>\n\u5bf9\u4e8e\u666e\u901a\u7684\u60c5\u51b5\uff0c\u6211\u4eec\u77e5\u9053\u89e3\u662f Catalan \u5e8f\u5217\uff0c\u4f46\u662f\u8fd9\u9898\u4e2d\u6709<br \/>\n+-+- A +-+- B<br \/>\n\u7c7b\u4f3c\u8fd9\u6837\u7684\u8868\u8fbe\u5f0f\u5b58\u5728\uff0c\u5f71\u54cd\u4e86\u6211\u4f5c\u51fa\u5224\u65ad\uff0c\u60f3\u4e86 12 \u5206\u949f\u6ca1\u6709\u4ec0\u4e48\u6709\u610f\u4e49\u7684\u7ed3\u679c\u4e8e\u662f\u8df3\u3002\u3002<\/p>\n<p>C \u662f\u4e00\u4e2a\u63d2\u5934DP\uff0c\u4f46\u662f\u611f\u89c9\u5bf9\u6211\u53ef\u80fd\u662f\u4e2a\u5751\u3002\u3002\u4e8e\u662f\u518d\u770b\u4e86\u4e00\u4e0b E\u3002\u3002<\/p>\n<p>E \u662f\u8bf4\u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a N \u7684\u8d5b\u9053\uff08\u6570\u8f74\uff09\uff0c\u4ee5\u53ca M \u573a\u6bd4\u8d5b\uff0c<br \/>\n\u6bcf\u573a\u6bd4\u8d5b\u5360\u7528\u4e00\u6bb5\u8fde\u7eed\u7684\u533a\u95f4\uff0c\u6bcf\u4e2a\u5355\u4f4d\u8d5b\u9053\u5982\u679c\u8981\u4f7f\u7528\u7684\u8bdd\uff0c\u6709\u4e00\u4e2a\u4fee\u590d\u7684\u4ee3\u4ef7\uff0c\u6bcf\u573a\u6bd4\u8d5b\u6709\u4e00\u4e2a\u6536\u76ca\uff0c\u6700\u5927\u5316\u6536\u76ca\u3002\u3002<\/p>\n<p>\u76ee\u6d4b\u4e86\u4e00\u4e0b\u51c6\u5907\u4e0a\u6700\u5927\u6743\u95ed\u5408\u5b50\u56fe\uff0c\u4f46\u662f\u6709\u4e00\u4e2a\u95ee\u9898\u3002\u3002<\/p>\n<p>\u3002\u3002N \u548c M \u90fd\u7b49\u4e8e 2 * 10^5\uff0c\u8fd9\u6837\u5982\u679c\u6bcf\u573a\u6bd4\u8d5b\u90fd\u4f9d\u8d56\u6574\u6bb5\u533a\u95f4\u7684\u8bdd\uff0c\u8fb9\u53ef\u80fd\u5b58\u4e0d\u4e0b\u3002\u60f3\u4e86\u4e00\u4e0b\u4f18\u5316\u5efa\u56fe\u3002\u3002\u6216\u8005\u80fd\u4e0d\u80fd\u79bb\u6563\u6389\u4ec0\u4e48\u7684\uff0c\u4f46\u662f\u6ca1\u6709\u4ec0\u4e48\u7ed3\u679c\u3002\u3002<br \/>\n\u4e8e\u662f\u6211\u8d4c\u5b83\u4e0d\u7a20\u5bc6\u3002\u3002\u3002\u3002<br \/>\n\uff08\u4e2d\u95f4\u679c\u7136\u88ab cha \u4e86\uff09<\/p>\n<p>\u5728 E \u88ab cha \u8fd9\u524d\u6211 yy \u4e86\u4e00\u4e0b D\u3002\u3002\u3002\u3002<br \/>\n\u6700\u540e C \u7684\u6ca1\u8c03\u51fa\u6765\u3002\u3002<\/p>\n<p>&#8212;&#8212;<br \/>\n\u89e3\u9898\u62a5\u544a\u51fa\u6765\u4e86\u3002\u3002D, E \u90fd\u6302\u4e86\u3002\u3002\u3002\u7b49\u4e0b\u6b21\u5427\u3002\u3002\u3002<\/p>\n<p>&#8212;&#8212;&#8212;-<br \/>\n\u8865\uff1a<br \/>\n\u597d\u5427\u3002\u3002\u9996\u5148 C \u53ea\u6709 \u90a3 4 \u79cd\u63d2\u5934\u3002\u3002\u4e8e\u662f\u53ea\u662f\u4e00\u9053\u627e Invariants \u7684\u9898\u76ee\u3002\u3002<br \/>\n\u3002\u3002\u3002\u7136\u540e\u8865\u4e00\u4e0b E \u3002\u3002\u76ee\u524d\u77e5\u9053\u4e09\u79cd\u4f5c\u6cd5\u3002\u3002\u5176\u4e2d\u7f51\u7edc\u6d41\u7684\u65b9\u6cd5\u4ecd\u7136\u6709\u95ee\u9898\u3002\u3002\u4f46\u6211\u8ba4\u4e3a\u5e94\u8be5\u4ee5\u540e\u53ef\u4ee5\u60f3\u51fa\u6539\u8fdb\u7684\u529e\u6cd5\u3002\u3002<\/p>\n<p>\u9996\u5148\u662f\u52a8\u6001\u89c4\u5212\u3002\u3002<\/p>\n<p>\u3002\u3002\u6211\u4eec\u7528 dp[i] \u8868\u793a \u5230\u524d i \u4e2a\u4f4d\u7f6e\u4e3a\u6b62\u6240\u80fd\u53d6\u5f97\u7684\u6700\u5927\u6536\u76ca\uff0c\u7b2c i \u4e2a\u4f4d\u7f6e\u53ef\u4ee5\u4fee\u4e5f\u53ef\u4ee5\u4e0d\u4fee\u3002<\/p>\n<p>\u90a3\u4e48 dp[i] = max{dp[j] + w(j, i)} | j < i} \u5176\u4e2d w(j, i) \u8868\u793a\u53ca\u6240\u6709\u65e5\u7a0b\u5305\u542b\u4e8e [j, i] \u8fd9\u6bb5\u7684\u8d5b\u4e8b\u6240\u80fd\u53d6\u5f97\u7684\u6536\u76ca\u548c \u51cf\u53bb \u4fee\u590d\u8fd9\u6bb5\u8def\u7684\u4ee3\u4ef7\u3002\n\u3002\u3002\u8fd9\u662f \u7b2c i \u4e2a\u4f4d\u7f6e\u5fc5\u987b\u8981\u4fee\u5fb7\uff0c\u6240\u4ee5\u518d checkMax(dp[i], dp[i-1]) .. .\n\n\u8fd9\u4e2a\u8f6c\u79fb\u65b9\u7a0b\u7684\u590d\u6742\u5ea6\u4f3c\u4e4e\u662f O(n2) \u800c\u4e14\u770b\u8d77\u6765\u5f97\u5230 w() \u4e5f\u4e0d\u662f\u5f88\u597d\u5199\u3002\u3002\n\u3002\u3002\u6b63\u786e\u7684\u505a\u6cd5\u662f\uff0c\u5c06 w() \u51fd\u6570\u8fde\u540c dp[] \u4e00\u8d77\u653e\u5230\u7ebf\u6bb5\u6811\u4e2d\u7ef4\u62a4\uff0c\u4e8e\u662f\u5f97\u5230\u4e00\u4e2a O(nlogn) \u7684\u65b9\u6cd5\u3002\n\n\u3002\u3002\u3002\u7136\u540e\u3002\u3002\u8fd9\u9898\u8fd8\u6709\u4e00\u79cd\u8d2a\u5fc3\u65b9\u6cd5 Orz\u3002\n\u3002\u8d34\u5728 <a href=\"http:\/\/www.codeforces.com\/blog\/entry\/2584\">Editorial<\/a> \u4e0b\u9762\u4e86\u3002\u3002<\/p>\n<p>\uff08\u636e\u8bf4\u8fd9\u4e2a\u9898\u662f\u51fa\u5230 <a href=\"http:\/\/www.ioi2011.or.th\/tasks\">\u4eca\u5e74 IOI<\/a> \u7136\u540e\u88ab Ban \u6389\u4e86\u3002\u3002\u56e0\u4e3a\u3002\u3002 IOI \u4e0d\u559c\u6b22\u7eaf\u6570\u503c\u8f93\u51fa\u7684\u9898\u76ee\u3002\u3002\uff09<\/p>\n<pre class=\"brush: cpp; collapse: true; light: false; title: DP; toolbar: true; notranslate\" title=\"DP\">\r\n\/* .................................................................................................................................. *\/\r\n\r\nconst int N = 200009;\r\nint C&#x5B;N], L&#x5B;N], R&#x5B;N], V&#x5B;N];\r\nVI events&#x5B;N];\r\n\r\nLL key&#x5B;4 * N], delay&#x5B;4 * N];\r\nint a, b; LL v;\r\nint n, m; LL res;\r\n\r\n#define root 1, 0, n\r\n#define lx (x &lt;&lt; 1)\r\n#define rx (lx + 1)\r\n#define lc lx, l, m\r\n#define rc rx, m+1, r\r\n\r\nvoid Inc(int x, LL d){\r\n    key&#x5B;x] += d, delay&#x5B;x] += d;\r\n}\r\n\r\nvoid Release(int x){\r\n    if (delay&#x5B;x] != 0){\r\n        key&#x5B;lx] += delay&#x5B;x], key&#x5B;rx] += delay&#x5B;x];\r\n        delay&#x5B;lx] += delay&#x5B;x], delay&#x5B;rx] += delay&#x5B;x];\r\n        delay&#x5B;x] = 0;\r\n    }\r\n}\r\n\r\nvoid Update(int x){\r\n    key&#x5B;x] = max(key&#x5B;lx], key&#x5B;rx]);\r\n}\r\n\r\nvoid Insert(int x, int l, int r){\r\n    if (a &lt;= l &amp;&amp; r &lt;= b){\r\n        Inc(x, v);\r\n    }\r\n    else {\r\n        Release(x);\r\n        int m = ((l + r) &gt;&gt; 1);\r\n        if (a &lt;= m) Insert(lc);\r\n        if (m &lt; b) Insert(rc);\r\n        Update(x);\r\n    }\r\n}\r\n\r\nint main(){\r\n\r\n    \/\/freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n    \/\/freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);\r\n\r\n    RD(n, m); REP_1(i, n) RD(C&#x5B;i]);\r\n    REP_1(i, m) RD(L&#x5B;i], R&#x5B;i], V&#x5B;i]), events&#x5B;R&#x5B;i]].PB(i);\r\n\r\n#define it events&#x5B;i]&#x5B;j]\r\n\r\n    REP_1(i, n){\r\n        REP(j, SZ(events&#x5B;i])){\r\n            a = 0, b = L&#x5B;it] - 1, v = V&#x5B;it];\r\n            Insert(root);\r\n        }\r\n\r\n        a = 0, b = i - 1, v = -C&#x5B;i];\r\n        Insert(root);\r\n\r\n        checkMax(res, key&#x5B;1]);\r\n        a = i, b = i, v = res;\r\n        Insert(root);\r\n    }\r\n\r\n    OT(res);\r\n}\r\n\r\n<\/pre>\n<pre class=\"brush: cpp; collapse: true; light: false; title: Greedy; toolbar: true; notranslate\" title=\"Greedy\">\r\n\/* .................................................................................................................................. *\/\r\n\r\nconst int N = 200009;\r\n\r\nint Lef&#x5B;N], Rgt&#x5B;N], Def&#x5B;N];\r\nint Att&#x5B;N]; VI events&#x5B;N];\r\nint n, m; LL res;\r\n\r\nstruct comp{\r\n    bool operator() (const int &amp;lhs, const int &amp;rhs) const{\r\n        return Rgt&#x5B;lhs] &gt; Rgt&#x5B;rhs];\r\n    }\r\n};\r\n\r\npriority_queue&lt;int, vector&lt;int&gt;, comp &gt; Q;\r\n\r\nint main(){\r\n    RD(n, m); REP_1(i, n) RD(Att&#x5B;i]);\r\n    REP_1(i, m) RD(Lef&#x5B;i], Rgt&#x5B;i], Def&#x5B;i]), events&#x5B;Lef&#x5B;i]].PB(i);\r\n\r\n#define it events&#x5B;i]&#x5B;j]\r\n\r\n    REP_1(i, n){\r\n        while (!Q.empty() &amp;&amp; Rgt&#x5B;Q.top()] &lt; i) res += Def&#x5B;Q.top()], Q.pop();\r\n        REP(j, SZ(events&#x5B;i])) Q.push(it);\r\n\r\n        while (!Q.empty() &amp;&amp; Att&#x5B;i]){\r\n            int delta = min(Att&#x5B;i], Def&#x5B;Q.top()]);\r\n            Att&#x5B;i] -= delta, Def&#x5B;Q.top()] -= delta;\r\n            if (!Def&#x5B;Q.top()]) Q.pop();\r\n        }\r\n    }\r\n    while (!Q.empty()) res += Def&#x5B;Q.top()], Q.pop();\r\n\r\n    OT(res);\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\uff08\u5728\u7f51\u5427\u505a CF \u7684\u5bc2\u5bde\u4f60\u4eec\u4e0d\u61c2\uff01\uff01\uff01\uff09 \u8fd9\u76d8\u662f TC \u9898\u5988 dolphinigle \u7684\u573a\u3002\u3002 A \u5f00\u59cb\u6ca1\u6709\u6ce8\u610f p[i] > i \u7684\u60c5\u51b5\u3002\u3002\u803d\u6401\u4e86\u4e00\u4e9b\u65f6\u95f4\u5728\u8c03\u8bd5\u4e0a\u3002 B \u7565\u3002\u3002 \u4e4b\u540e\u5148\u8bfb\u4e86 D\uff0c\u662f\u4e00\u4e2a\u7ed9\u5b9a\u4e00\u4e2a\u8868\u8fbe\u5f0f\uff0c\u95ee\u52a0\u62ec\u53f7\u6570\u76ee\u7684\u9898\u76ee\uff0c \u5bf9\u4e8e\u666e\u901a\u7684\u60c5\u51b5\uff0c\u6211\u4eec\u77e5\u9053\u89e3\u662f Catalan \u5e8f\u5217\uff0c\u4f46\u662f\u8fd9\u9898\u4e2d\u6709 +-+- A +-+- B \u7c7b\u4f3c\u8fd9\u6837\u7684\u8868\u8fbe\u5f0f\u5b58\u5728\uff0c\u5f71\u54cd\u4e86\u6211\u4f5c\u51fa\u5224\u65ad\uff0c\u60f3\u4e86 12 \u5206\u949f\u6ca1\u6709\u4ec0\u4e48\u6709\u610f\u4e49\u7684\u7ed3\u679c\u4e8e\u662f\u8df3\u3002\u3002 C \u662f\u4e00\u4e2a\u63d2\u5934DP\uff0c\u4f46\u662f\u611f\u89c9\u5bf9\u6211\u53ef\u80fd\u662f\u4e2a\u5751\u3002\u3002\u4e8e\u662f\u518d\u770b\u4e86\u4e00\u4e0b E\u3002\u3002 E \u662f\u8bf4\u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a N \u7684\u8d5b\u9053\uff08\u6570\u8f74\uff09\uff0c\u4ee5\u53ca M \u573a\u6bd4\u8d5b\uff0c \u6bcf\u573a\u6bd4\u8d5b\u5360\u7528\u4e00\u6bb5\u8fde\u7eed\u7684\u533a\u95f4\uff0c\u6bcf\u4e2a\u5355\u4f4d\u8d5b\u9053\u5982\u679c\u8981\u4f7f\u7528\u7684\u8bdd\uff0c\u6709\u4e00\u4e2a\u4fee\u590d\u7684\u4ee3\u4ef7\uff0c\u6bcf\u573a\u6bd4\u8d5b\u6709\u4e00\u4e2a\u6536\u76ca\uff0c\u6700\u5927\u5316\u6536\u76ca\u3002\u3002 \u76ee\u6d4b\u4e86\u4e00\u4e0b\u51c6\u5907\u4e0a\u6700\u5927\u6743\u95ed\u5408\u5b50\u56fe\uff0c\u4f46\u662f\u6709\u4e00\u4e2a\u95ee\u9898\u3002\u3002 \u3002\u3002N \u548c M \u90fd\u7b49\u4e8e 2 * 10^5\uff0c\u8fd9\u6837\u5982\u679c\u6bcf\u573a\u6bd4\u8d5b\u90fd\u4f9d\u8d56\u6574\u6bb5\u533a\u95f4\u7684\u8bdd\uff0c\u8fb9\u53ef\u80fd\u5b58\u4e0d\u4e0b\u3002\u60f3\u4e86\u4e00\u4e0b\u4f18\u5316\u5efa\u56fe\u3002\u3002\u6216\u8005\u80fd\u4e0d\u80fd\u79bb\u6563\u6389\u4ec0\u4e48\u7684\uff0c\u4f46\u662f\u6ca1\u6709\u4ec0\u4e48\u7ed3\u679c\u3002\u3002 \u4e8e\u662f\u6211\u8d4c\u5b83\u4e0d\u7a20\u5bc6\u3002\u3002\u3002\u3002 \uff08\u4e2d\u95f4\u679c\u7136\u88ab cha \u4e86\uff09 \u5728 E \u88ab cha \u8fd9\u524d\u6211 [&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":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[18],"tags":[],"class_list":["post-49","post","type-post","status-publish","format-standard","hentry","category-codeforces"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-N","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/49","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=49"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/49\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=49"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=49"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=49"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}