{"id":1067,"date":"2014-11-07T04:16:46","date_gmt":"2014-11-06T20:16:46","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=1067"},"modified":"2014-11-07T06:28:24","modified_gmt":"2014-11-06T22:28:24","slug":"codeforces-round-276","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/codeforces-round-276\/","title":{"rendered":"Codeforces Round #276"},"content":{"rendered":"<p><!--more--><\/p>\n<h2>Problem A. Bits<\/h2>\n<p>\u627e\u5230 [l, r] \u4e4b\u95f4 count_bits() \u6700\u591a\u7684\u6570\u3002\u3002\u3002<br \/>\n\u9996\u5148 ans = l\u3002\u3002\u3002\u7136\u540e\u8fed\u4ee3\u3002\u3002\u3002\u6bcf\u6b21\u628a\u6700\u4f4e\u4f4d\u7684 0 \u8865\u6210 1\u3002\u3002\u3002<br \/>\n\u540e\u8005\u53ef\u4ee5\u901a\u8fc7 l |= l+1 \u5b9e\u73b0\u3002\u3002<\/p>\n<pre class=\"brush: python; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\nfor i in range(int(input())):\r\n l,r=map(int,input().split())\r\n while(l|(l+1)&lt;=r): l|=l+1\r\n print(l)\r\n<\/pre>\n<h2>Problem B. Maximum Value<\/h2>\n<p>\u7ed9\u5b9a\u4e00\u5806\u6570\u3002<br \/>\n\u95ee\u6700\u5927\u7684 x%y \u7684\u503c\u3002\u3002\u8981\u6c42 x>=y\u3002\u3002<\/p>\n<p>O(nqrtn) \u7b97\u6cd5\uff1a<br \/>\n\u6211\u4eec\u6709\uff1ax\uff1dqy\uff0br<br \/>\n\u3002\u3002\u679a\u4e3e y\u3002\u3002\u3002\u7136\u540e\u679a\u4e3e q\u3002<br \/>\n\u7136\u540e\u6bcf\u6b21\u627e\u5230\u5c0f\u4e8e qy \u7684\u6700\u5927\u7684\u6570\u5373\u53ef\u3002<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\nconst int N = int(2e6) + 9;\r\nint a&#x5B;N];\r\nint n;\r\n\r\nint main(){\r\n\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n    \/\/freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n\r\n\tREP_C(i, RD(n)){\r\n\t    int ai; RD(ai);\r\n\t    a&#x5B;ai] = ai;\r\n\t}\r\n\r\n\tFOR(i, 1, N) checkMax(a&#x5B;i], a&#x5B;i-1]);\r\n\r\n\t\/\/ x = qy + r\r\n\r\n\tint z = 0; FOR(y, 1, N) if (a&#x5B;y] == y){\r\n\t    for (int qy=y;qy+y-1&lt;N;qy+=y) checkMax(z, a&#x5B;qy+y-1]-qy);\r\n\t}\r\n\r\n\tOT(z);\r\n}\r\n<\/pre>\n<p>O(n) \u7b97\u6cd5\uff1a<br \/>\n\u901a\u8fc7\u7c7b\u4f3c\u7b5b\u6cd5\uff0c\u5f97\u5230\u6bcf\u4e2a\u6570\u7684\u6700\u5927\u7ea6\u6570\u3002<br \/>\n\u7528\u8fd9\u4e2a\u53ef\u4ee5\u5e72\u561b\uff1f<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n\r\nconst int N = int(1e6) + 9;\r\nint a&#x5B;N];\r\nint n;\r\n\r\nint main(){\r\n\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n    \/\/freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n\r\n\tREP_C(i, RD(n)){\r\n\t    int ai; RD(ai);\r\n\t    a&#x5B;ai] = ai;\r\n\t}\r\n\r\n\r\n\tint z = 0, t = 1; REP(i, N) if (a&#x5B;i]){\r\n        checkMax(t, i); while (t&lt;N &amp;&amp; t&lt;i+a&#x5B;i]){\r\n            \/\/cout &lt;&lt; t &lt;&lt; &quot; &quot;&lt;&lt; i &lt;&lt; endl;\r\n            if (a&#x5B;t] == t) checkMax(z, t-i);\r\n            ++t;\r\n        }\r\n        if (i+a&#x5B;i]&lt;N) checkMax(a&#x5B;i+a&#x5B;i]], a&#x5B;i]);\r\n    }\r\n\r\n\tOT(z);\r\n}\r\n\r\n<\/pre>\n<h2>Problem C. Strange Sorting<\/h2>\n<h2>Problem D. Kindergarten<\/h2>\n<h3>Brief description: <\/h3>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4 A[]\uff0c\u6309\u987a\u5e8f\u5206\u6210\u4e00\u4e9b\u8fde\u7eed\u7684\u7ec4\uff0c\u6bcf\u7ec4\u7684\u8d21\u732e\u662f\u7ec4\u4e2d\u6700\u5927\u7684\u6570\u4e0e\u6700\u5c0f\u6570\u7684\u7edd\u5bf9\u503c\u3002<br \/>\n\u6c42\u4e00\u79cd\u5206\u7ec4\u65b9\u6848\uff0c\u4f7f\u5f97\u6240\u6709\u7ec4\u7684\u8d21\u732e\u7684\u548c\u6700\u5927\u3002<\/p>\n<h3>Analysis: <\/h3>\n<p>\u7531\u4e8e\u6700\u5927\u3001\u6700\u5c0f\u7684\u6570\u4e00\u5b9a\u662f\u5904\u5728\u7ec4\u7684\u7aef\u70b9\u3002\u3002\u3002<br \/>\n\u6240\u4ee5\u4e0d\u96be\u5199\u51fa\u5982\u4e0b DP\uff1a<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n    REP_1(i, n){\r\n        REP_1(j, i-1){\r\n            checkMax(dp&#x5B;i], dp&#x5B;j-1] + abs(A&#x5B;i] - A&#x5B;j]));\r\n        }\r\n    }\r\n<\/pre>\n<p>\u7136\u540e\u628a\u7edd\u5bf9\u503c\u62c6\u5f00\u3002\u3002<br \/>\n\u7528\u4e24\u4e2a\u6811\u72b6\u6570\u7ec4\u8bb0\u5f55\u4e00\u4e0b\u5c31\u884c\u4e86 <a href=\"http:\/\/codeforces.com\/contest\/484\/submission\/8596652\">http:\/\/codeforces.com\/contest\/484\/submission\/8596652<\/a><br \/>\n\u590d\u6742\u5ea6 $$O(nlogn)$$\u3002\u3002\u3002<\/p>\n<p>\u770b\u4e86\u5b98\u65b9 <a href=\"http:\/\/codeforces.com\/blog\/entry\/14592\">\u9898\u89e3<\/a> \u624d\u53d1\u73b0\u5e94\u8be5\u7528 $$O(n)$$ \u7684\u505a\u6cd5\u3002\u3002\u3002<br \/>\n\u56e0\u4e3a\u6bcf\u7ec4\u7684\u6570\u4e00\u5b9a\u662f\u5355\u8c03\u7684\u3002\u3002\u3002<\/p>\n<p>\u56e0\u6b64\u6f5c\u5728\u7684\u8f6c\u79fb\u4f4d\u7f6e\u53ea\u6709 3 \u4e2a\u3002\u3002\u3002\uff08Paying attention to the interesting points in sequence which making local maximums (i. e. ai\u2009-\u20091\u2009<\u2009ai\u2009>\u2009ai\u2009+\u20091), local minimums (ai\u2009-\u20091\u2009>\u2009ai\u2009<\u2009ai\u2009+\u20091), and point adjacent to them\u3002\uff09\n\n\u8bb0\u5f55\u4e00\u4e0b\u5c31\u884c\u4e86\u3002\u3002\u3002\n\n\n\n\n<h2>Problem E. Sign on Fence<\/h2>\n<h3>Brief description: <\/h3>\n<p>\u7ed9\u5b9a\u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4 $h_i$\u3002\u3002<br \/>\n\u6bcf\u6b21\u56de\u7b54\u8be2\u95ee\uff1a<code> l, r, w <\/code>\u3002\u3002\u8868\u793a\u6c42\uff1a<br \/>\n $$!\\max_{l \\leq i \\leq r-w+1} \\min_{i\\leq j\\leq i+w-1}h_i$$<br \/>\n\uff08[l, r] \u4e4b\u95f4\uff0c\u957f\u5ea6\u4e3a w \u7684\u8fde\u7eed\u6bb5\u91cc\uff0c\u6700\u5c0f\u503c\u7684\u6700\u5927\u503c\u3002\u3002\u3002\uff09<\/p>\n<h3>Analysis: <\/h3>\n<p>\u5148\u5199\u4e00\u4e2a\u652f\u6301\u533a\u95f4\u6c42\u6700\u5927\u6d4b\u5ea6\u7684\u7ebf\u6bb5\u6811\u3002\u3002\u3002<br \/>\n\u7136\u540e cdq \u5206\u6cbb\u3002\u3002\u540c <a href=\"https:\/\/www.shuizilong.com\/house\/archives\/bzoj-2527-poi2011meteors\/\">BZOJ 2527. [Poi2011]Meteors<\/a><\/p>\n<p>\uff08\u6839\u636e <a href=\"http:\/\/codeforces.com\/blog\/entry\/14592#comment-195898\">Swistakk \u7684\u7559\u8a00<\/a>\u3002\u3002\u539f\u6765\u8fd9\u79cd\u65b9\u6cd5\u66f4\u5408\u9002\u7684\u540d\u5b57\u662f &#8220;parallel binary search&#8221;\u3002\uff09<\/p>\n<p><a href=\"http:\/\/codeforces.com\/contest\/484\/submission\/8596944\">http:\/\/codeforces.com\/contest\/484\/submission\/8596944<\/a><\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n\r\n\/\/}\/* .................................................................................................................................. *\/\r\n\r\nconst int N = int(3e5) + 9;\r\n\r\nint A&#x5B;N], ans&#x5B;N];\r\nint n;\r\n\r\nVI P;\r\n\r\nstruct rec{\r\n    int ll, rr, mx; bool full;\r\n    void reset(int t){\r\n        ll = rr = mx = t;\r\n        full = t;\r\n    }\r\n    void upd(const rec l, const rec r){\r\n        full = l.full &amp;&amp; r.full;\r\n        mx = max(l.mx, r.mx, l.rr + r.ll);\r\n        ll = max(l.ll, l.full ? l.ll + r.ll : 0);\r\n        rr = max(r.rr, r.full ? r.rr + l.rr : 0);\r\n    }\r\n};\r\n\r\nnamespace ST{\r\n\r\n#define lx (x &lt;&lt; 1)\r\n#define rx (lx | 1)\r\n#define ml (l+r&gt;&gt;1)\r\n#define mr (ml+1)\r\n#define lc lx,l,ml\r\n#define rc rx,mr,r\r\n#define rt 1,1,n\r\n\r\n    rec T&#x5B;4*N]; int a, b;\r\n    rec Q(int x, int l, int r){\r\n        if (b &lt; l || r &lt; a) return rec();\r\n        if (a &lt;= l &amp;&amp; r &lt;= b){\r\n            return T&#x5B;x];\r\n        }\r\n        else{\r\n            rec ll = Q(lc), rr = Q(rc);\r\n            rec zz; zz.upd(ll, rr);\r\n            return zz;\r\n        }\r\n    }\r\n\r\n    int Q(int _a, int _b){\r\n        a = _a, b = _b;\r\n        return Q(rt).mx;\r\n    }\r\n\r\n    void Add(int x, int l, int r){\r\n        if (l == r){\r\n            T&#x5B;x].reset(b);\r\n        }\r\n        else{\r\n            if (a &lt; mr) Add(lc); else Add(rc);\r\n            T&#x5B;x].upd(T&#x5B;lx], T&#x5B;rx]);\r\n        }\r\n    }\r\n    void Add(int x){\r\n        a = x, b = 1;\r\n        Add(rt);\r\n    }\r\n    void Del(int x){\r\n        a = x, b = 0;\r\n        Add(rt);\r\n    }\r\n};\r\n\r\nstruct Query{\r\n    int l, r, w;\r\n    void in(){\r\n        RD(l,r,w);\r\n    }\r\n    bool ok(){\r\n        return ST::Q(l,r) &gt;= w;\r\n    }\r\n} Q&#x5B;N]; VI op&#x5B;N];\r\n\r\nvoid cdq(const VI I, int l, int r){\r\n    if (l + 1 == r){\r\n        ECH(i, I) ans&#x5B;*i] = l;\r\n    }\r\n    else{\r\n        int m = l + r &gt;&gt; 1;\r\n\r\n        FOR(i, l, m) ECH(it, op&#x5B;i]) ST::Add(*it);\r\n\r\n        VI Il, Ir; ECH(i, I){\r\n            if (Q&#x5B;*i].ok()){\r\n                Il.PB(*i);\r\n            }\r\n            else{\r\n                Ir.PB(*i);\r\n            }\r\n        }\r\n\r\n        cdq(Ir, m, r); FOR(i, l, m) ECH(it, op&#x5B;i]) ST::Del(*it);\r\n        cdq(Il, l, m);\r\n    }\r\n}\r\n\r\nint main(){\r\n\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n    \/\/freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n\r\n    REP_1_C(i, RD(n)) P.PB(RD(A&#x5B;i]));\r\n    UNQ(P); REP_1(i, n) op&#x5B;P.size()-LBD(P, A&#x5B;i])-1].PB(i);\r\n    int m; VI I; REP_1_C(i, RD(m)) Q&#x5B;i].in(), I.PB(i);\r\n\r\n    cdq(I, 0, P.size());\r\n    REP_1(i, m) OT(P&#x5B;P.size()-ans&#x5B;i]-1]);\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"","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-1067","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-hd","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1067","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=1067"}],"version-history":[{"count":1,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1067\/revisions"}],"predecessor-version":[{"id":1068,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1067\/revisions\/1068"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=1067"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=1067"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=1067"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}