{"id":1025,"date":"2014-10-11T23:05:37","date_gmt":"2014-10-11T15:05:37","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=1025"},"modified":"2014-10-11T23:08:22","modified_gmt":"2014-10-11T15:08:22","slug":"bzoj-1176-balkan2007mokia","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/bzoj-1176-balkan2007mokia\/","title":{"rendered":"BZOJ 1176. [Balkan2007]Mokia"},"content":{"rendered":"<p><!--more--><br \/>\n\u7ef4\u62a4\u4e00\u4e2a W*W \u7684\u77e9\u9635\uff0c\u6bcf\u6b21\u64cd\u4f5c\u53ef\u4ee5\u589e\u52a0\u67d0\u683c\u5b50\u7684\u6743\u503c\uff0c\u6216\u8be2\u95ee\u67d0\u5b50\u77e9\u9635\u7684\u603b\u6743\u503c\u3002 \u4fee\u6539\u64cd\u4f5c\u6570 M<=160000\uff0c\u8be2\u95ee\u6570 Q<=10000\uff0cW<=2000000\u3002\n\n\u3002\u3002\u3002 cdq \u5206\u6cbb + \u626b\u63cf\u7ebf\u3002\n\u3002\u5f3a\u884c\u79bb\u7ebf\u3002\u5c06\u4e8c\u7ef4\u6811\u72b6\u6570\u7ec4\u964d\u6210\u4e00\u7ef4\u3002\u3002\u3002\n\nhttp:\/\/www.lydsy.com\/JudgeOnline\/problem.php?id=1176\n<a href=\"https:\/\/gist.github.com\/lychees\/d677c384dbe09fea8e02\">https:\/\/gist.github.com\/lychees\/d677c384dbe09fea8e02<\/a><\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n\/\/}\/* .................................................................................................................................. *\/\r\n\r\nconst int N = int(2e5) + 9;\r\nint n;\r\n\r\nnamespace BIT{\r\n    const int N = 2000009;\r\n    typedef LL intt;\r\n    intt C&#x5B;N], n;\r\n    void Add(int x, int d){\r\n        for (;x&lt;=n;x+=low_bit(x)) C&#x5B;x] += d;\r\n    }\r\n    intt Sum(int x){\r\n        intt res = 0; for (;x;x^=low_bit(x)) res += C&#x5B;x];\r\n        return res;\r\n    }\r\n    intt Sum(int l, int r){\r\n        return Sum(r) - Sum(l-1);\r\n    }\r\n} \/\/using namespace BIT;\r\n\r\nstruct Op{\r\n    int x1, y1, x2, y2, ty; LL d;\r\n    void in(int _ty){\r\n        ty = _ty;\r\n\r\n        if (ty == 1){\r\n            RD(x1, y1, d);\r\n        }\r\n        else if (ty == 2){\r\n            RD(x1, y1, x2, y2);\r\n            d = 0;\r\n        }\r\n    }\r\n}; vector&lt;Op&gt; op;\r\n\r\nvoid cdq(int l, int r){\r\n    if (l + 1 == r){\r\n\r\n    }\r\n    else{\r\n        int m = l + r &gt;&gt; 1;\r\n\r\n        static PII Q&#x5B;N]; int qn = 0;\r\n\r\n        FOR(i, l, m) if (op&#x5B;i].ty == 1) Q&#x5B;qn++] = MP(op&#x5B;i].x1, i);\r\n        FOR(i, m, r) if (op&#x5B;i].ty == 2){\r\n            Q&#x5B;qn++] = MP(op&#x5B;i].x1-1, i);\r\n            Q&#x5B;qn++] = MP(op&#x5B;i].x2, i);\r\n        }\r\n\r\n        sort(Q, Q+qn);\r\n\r\n        REP(i, qn){\r\n\r\n            int id = Q&#x5B;i].se;\r\n\r\n            if (op&#x5B;id].ty == 2){ \/\/ Query\r\n                if (Q&#x5B;i].fi + 1 == op&#x5B;id].x1){ \/\/ Left\r\n                    op&#x5B;id].d -= BIT::Sum(op&#x5B;id].y1, op&#x5B;id].y2);\r\n                }\r\n                else{ \/\/ Right\r\n                    op&#x5B;id].d += BIT::Sum(op&#x5B;id].y1, op&#x5B;id].y2);\r\n                }\r\n            }\r\n            else{\r\n                BIT::Add(op&#x5B;id].y1, op&#x5B;id].d);\r\n            }\r\n        }\r\n\r\n        REP(i, qn){\r\n            int id = Q&#x5B;i].se;\r\n\r\n            if (op&#x5B;id].ty == 2){ \/\/ Query\r\n\r\n            }\r\n            else{\r\n                BIT::Add(op&#x5B;id].y1, -op&#x5B;id].d);\r\n            }\r\n        }\r\n\r\n        cdq(l, m); cdq(m, r);\r\n    }\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    int init_value; RD(init_value, BIT::n);\r\n    assert(init_value == 0);\r\n\r\n    do{\r\n        int ty; RD(ty); if (ty == 3) break;\r\n        Op t; t.in(ty); op.PB(t);\r\n    } while (1);\r\n\r\n    cdq(0, SZ(op));\r\n    ECH(it, op) if (it-&gt;ty == 2){\r\n        OT(it-&gt;d);\r\n    }\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":[134],"class_list":["post-1025","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-cdq-"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-gx","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1025","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=1025"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1025\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=1025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=1025"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=1025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}