{"id":287,"date":"2012-05-04T13:09:42","date_gmt":"2012-05-04T05:09:42","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=287"},"modified":"2012-07-13T19:49:18","modified_gmt":"2012-07-13T11:49:18","slug":"swustjudge-857-illume-the-light","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/swustjudge-857-illume-the-light\/","title":{"rendered":"SwustJudge 857. Illume The Light"},"content":{"rendered":"<h3>Brief description: <\/h3>\n<p>\u7ed9\u5b9a\u4e00\u9897\u6811\uff0c\u6bcf\u4e2a\u7ed3\u70b9\u9ed1\u767d\u4e24\u79cd\u989c\u8272\uff0c\u52a8\u6001\u7ef4\u62a4\u4ee5\u4e0b\u8be2\u95ee\uff1a<br \/>\n\u3002\u3002\u6bcf\u6b21\u64cd\u4f5c\u4e00\u6761\u8fb9\uff0c\u5c06\u7ed3\u70b9\u6570\u8f83\u591a\u7684\u4e00\u4fa7\u7684\u989c\u8272\u53d6\u53cd\u3002\uff08\u5982\u76f8\u7b49\u5219\u5168\u90e8\u53d6\u53cd\u3002\u3002<br \/>\n\u3002\u3002\u6bcf\u6b21\u8be2\u95ee\u4e00\u6761\u8fb9\uff0c\u56de\u7b54\u7ed3\u70b9\u6570\u8f83\u591a\u4e00\u4fa7\u7684\u767d\u8272\u6570\u3002\uff08\u5982\u76f8\u7b49\u5219\u8f93\u51fa \u201cOh, my dear SWUST\u201d \u3002\u3002\u3002<\/p>\n<p><!--more--><\/p>\n<h3>Analysis: <\/h3>\n<p>&#8230;\uff08\u7565\u3002DFS \u5e8f\u5217 + \u7ebf\u6bb5\u6811\u3002\u3002\u3002<br \/>\n\u3002\u3002\u6ce8\uff1a<a href=\"http:\/\/user.qzone.qq.com\/494917509?ptlang=2052\">\u96ea\u96e8\u5fc3\u98de@USCT<\/a> \u51fa\u7684\u9898\u3002\u3002\u7136\u540e\u6211\u53c2\u4e0e\u7684\u9a8c\u9898\u3002\u3002\u7136\u540e\u8c8c\u4f3c\u6302\u4e0a\u53bb\u7684\u6570\u636e\u6709\u8bef\u3002\u3002\u3002\u3002\uff09<\/p>\n<pre class=\"brush: cpp; collapse: true; first-line: 1; light: false; title: SwustJudge 857. Illume The Light.cpp; toolbar: true; notranslate\" title=\"SwustJudge 857. Illume The Light.cpp\">\r\nconst int N = 100109, M = 2 * N;\r\n\r\nint L&#x5B;N], R&#x5B;N], sz&#x5B;N], hd&#x5B;N], h&#x5B;N], cnt;\r\n\/\/ Vertex\r\nint nxt&#x5B;M], a&#x5B;M], b&#x5B;M];\r\n\/\/ Adjacent list\r\nint C&#x5B;4*N], rev&#x5B;4*N], root = 1;\r\n\/\/ Interval Tree\r\nint n, m, n2, _;\r\n\r\n#define lx (x&lt;&lt;1)\r\n#define rx (lx|1)\r\n#define m ((l+r)&gt;&gt;1)\r\n#define lc lx, l, m, a, b\r\n#define rc rx, m+1, r, a, b\r\n#define len (r - l + 1)\r\n#define Release if (rev&#x5B;x]) C&#x5B;x] = len - C&#x5B;x], rev&#x5B;lx] ^= true, rev&#x5B;rx] ^= true, rev&#x5B;x] = false\r\n#define Update C&#x5B;x] = (rev&#x5B;lx] ? (m - l + 1) - C&#x5B;lx] : C&#x5B;lx]) + (rev&#x5B;rx] ? (r - m) - C&#x5B;rx] : C&#x5B;rx])\r\n\r\nint Modify(int x = root, int l = 1, int r = n, int a = 1, int b = n){\r\n    if (a &lt;= l &amp;&amp; r &lt;= b){\r\n        rev&#x5B;x] ^= true;\r\n    }\r\n    else {\r\n        Release; if (a &lt;= m) Modify(lc); if (m &lt; b) Modify(rc);\r\n        Update;\r\n    }\r\n}\r\n\r\nint Query(int x = root, int l = 1, int r = n, int a = 1, int b = n){\r\n    if (a &lt;= l &amp;&amp; r &lt;= b){\r\n        return rev&#x5B;x] ? len - C&#x5B;x] : C&#x5B;x];\r\n    }\r\n    else{\r\n        Release; return (a &lt;= m ? Query(lc) : 0) + (m &lt; b ? Query(rc) : 0);\r\n    }\r\n}\r\n\r\n#define v b&#x5B;i]\r\n\r\ninline void dfs(int u = 0){\r\n    L&#x5B;u] = ++cnt; sz&#x5B;u] = 1; for (int i=hd&#x5B;u];i;i=nxt&#x5B;i]) if (!L&#x5B;v]){\r\n        dfs(h&#x5B;i&gt;&gt;1]=v), sz&#x5B;u] += sz&#x5B;v];\r\n    }\r\n    R&#x5B;u] = cnt;\r\n}\r\n\r\n#undef m\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;swust.in&quot;, &quot;r&quot;, stdin);\r\n    \/\/freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n\r\n    Rush{\r\n\r\n        RD(n, m); FOR_C(i, 2, n &lt;&lt; 1){\r\n            RD(_, a&#x5B;i], b&#x5B;i]), --a&#x5B;i], --b&#x5B;i], a&#x5B;i|1] = b&#x5B;i], b&#x5B;i|1] = a&#x5B;i];\r\n            nxt&#x5B;i] = hd&#x5B;a&#x5B;i]], hd&#x5B;a&#x5B;i]] = i; ++i;\r\n            nxt&#x5B;i] = hd&#x5B;a&#x5B;i]], hd&#x5B;a&#x5B;i]] = i;\r\n        }\r\n\r\n        dfs(); char cmd&#x5B;9]; int x; DO(m){\r\n            RS(cmd); x = h&#x5B;RD()];\r\n            if (cmd&#x5B;0] == 'Q'){\r\n                if (sz&#x5B;x] == n\/2){\r\n                    puts(&quot;Oh, my dear SWUST&quot;);\r\n                }\r\n                else if (sz&#x5B;x] &gt; n\/2){\r\n                    OT(Query(root, 1, n, L&#x5B;x], R&#x5B;x]));\r\n                }\r\n                else {\r\n                    OT(Query() - Query(root, 1, n, L&#x5B;x], R&#x5B;x]));\r\n                }\r\n            }\r\n            else {\r\n                if (sz&#x5B;x] == n\/2) Modify();\r\n                else {\r\n                    if (sz&#x5B;x] &lt; n\/2) Modify();\r\n                    Modify(root, 1, n, L&#x5B;x], R&#x5B;x]);\r\n                }\r\n            }\r\n        }\r\n\r\n        RST(hd, nxt, a, b, sz);\r\n        RST(L, R, C, rev), cnt = 0;\r\n    }\r\n}\r\n<\/pre>\n<h3>External link: <\/h3>\n<p><a href=\"http:\/\/acm.swust.edu.cn\/oj\/problem\/857\/\">http:\/\/acm.swust.edu.cn\/oj\/problem\/857\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Brief description: \u7ed9\u5b9a\u4e00\u9897\u6811\uff0c\u6bcf\u4e2a\u7ed3\u70b9\u9ed1\u767d\u4e24\u79cd\u989c\u8272\uff0c\u52a8\u6001\u7ef4\u62a4\u4ee5\u4e0b\u8be2\u95ee\uff1a \u3002\u3002\u6bcf\u6b21\u64cd\u4f5c\u4e00\u6761\u8fb9\uff0c\u5c06\u7ed3\u70b9\u6570\u8f83\u591a\u7684\u4e00\u4fa7\u7684\u989c\u8272\u53d6\u53cd\u3002\uff08\u5982\u76f8\u7b49\u5219\u5168\u90e8\u53d6\u53cd\u3002\u3002 \u3002\u3002\u6bcf\u6b21\u8be2\u95ee\u4e00\u6761\u8fb9\uff0c\u56de\u7b54\u7ed3\u70b9\u6570\u8f83\u591a\u4e00\u4fa7\u7684\u767d\u8272\u6570\u3002\uff08\u5982\u76f8\u7b49\u5219\u8f93\u51fa \u201cOh, my dear SWUST\u201d \u3002\u3002\u3002<\/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":[16],"tags":[],"class_list":["post-287","post","type-post","status-publish","format-standard","hentry","category-online-judge"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-4D","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/287","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=287"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/287\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}