{"id":1286,"date":"2024-11-24T09:00:00","date_gmt":"2024-11-24T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=1286"},"modified":"2024-11-05T02:28:54","modified_gmt":"2024-11-04T18:28:54","slug":"zerojudge-a813","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-a813\/","title":{"rendered":"ZeroJudge A813: Viewing City"},"content":{"rendered":"\n\n\n<p>\u5728\u9ad8\u96c4\u5e02\u7684\u67d0\u8857\u9053\u4e0a\uff0c\u6709\u8a31\u591a\u9ad8\u77ee\u4e0d\u7b49\u7684\u623f\u5b50\u6392\u6210\u6574\u9f4a\u7684\u4e00\u5217\u3002<\/p>\n\n\n\n<p>\u5c0d\u65bc\u5169\u68df\u4e0d\u540c\u7684\u623f\u5b50 A \u8207 B \u4f86\u8aaa\uff0c\u5982\u679c\u623f\u5b50 A \u8207\u623f\u5b50 B \u4e4b\u9593\u7684\u6240\u6709\u5176\u4ed6\u623f\u5b50\u9ad8\u5ea6\uff0c\u90fd\u540c\u6642\u4e0d\u8d85\u904e\u623f\u5b50 A \u8207\u623f\u5b50 B \u7684\u9ad8\u5ea6\uff0c\u5247\u7ad9\u5728\u623f\u5b50 A \u4e0a\u9762\u7684\u4eba\u53ef\u4ee5\u770b\u5230\u623f\u5b50 B\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"205\" loading=\"lazy\" src=\"https:\/\/seanxd.com\/wp-content\/uploads\/2024\/11\/image-2-1024x205.webp\" alt=\"ZeroJudge A813 \u984c\u76ee\u89e3\u8aaa\" class=\"wp-image-1287\" srcset=\"https:\/\/seanxd.com\/wp-content\/uploads\/2024\/11\/image-2-1024x205.webp 1024w, https:\/\/seanxd.com\/wp-content\/uploads\/2024\/11\/image-2-300x60.webp 300w, https:\/\/seanxd.com\/wp-content\/uploads\/2024\/11\/image-2-768x154.webp 768w, https:\/\/seanxd.com\/wp-content\/uploads\/2024\/11\/image-2-18x4.webp 18w, https:\/\/seanxd.com\/wp-content\/uploads\/2024\/11\/image-2-50x10.webp 50w, https:\/\/seanxd.com\/wp-content\/uploads\/2024\/11\/image-2-100x20.webp 100w, https:\/\/seanxd.com\/wp-content\/uploads\/2024\/11\/image-2-png.webp 1368w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u5982\u4e0a\u5716\uff0c\u7531\u5de6\u81f3\u53f3\u5171\u6709\u4e94\u68df\u623f\u5b50\uff0c\u5176\u9ad8\u5ea6\u5206\u5225\u70ba 5\u30012\u30013\u30014\u30014\u3002\u7576\u6211\u5011\u7ad9\u5728\u6700\u53f3\u908a\u7684\u623f\u5b50\u4e0a\uff0c\u56e0\u70ba\u6211\u5011\u6240\u5728\u7684\u623f\u5b50\u9ad8\u5ea6\u70ba 4\uff0c\u8207\u6700\u5de6\u908a\u7684\u623f\u5b50 (\u9ad8\u5ea6 5) \u4e4b\u9593\u7684\u6240\u6709\u5176\u4ed6\u623f\u5b50 (\u9ad8\u5ea6\u70ba 2\u30013\u30014) \u90fd\u4e0d\u8d85\u904e\u6240\u5728\u7684\u623f\u5b50 (\u9ad8\u5ea6 4) \u53ca\u6700\u5de6\u908a\u7684\u623f\u5b50 (\u9ad8\u5ea6 5\uff09\uff0c\u6545\u6211\u5011\u53ef\u4ee5\u770b\u5230\u6700\u5de6\u908a\u7684\u623f\u5b50\u3002\u540c\u7406\uff0c\u6211\u5011\u4e5f\u80fd\u770b\u5230\u53f3\u908a\u7b2c\u4e8c\u68df\u623f\u5b50\u3002<\/p>\n\n\n\n<p>\u7d66\u4f60\u4e00\u689d\u8857\u9053\u5f9e\u5de6\u81f3\u53f3\u7684\u6240\u6709\u623f\u5b50\u9ad8\u5ea6\uff0c\u8a2d\u6709 N \u68df\u623f\u5b50\uff0c\u7ad9\u5728\u7b2c k \u68df\u623f\u5b50\u4e0a\u9762\u7684\u4eba\uff0c\u6240\u80fd\u770b\u898b\u7684\u5176\u4ed6\u623f\u5b50\u7e3d\u6578\u70ba C<sub>k<\/sub>\uff0c\u5247\u8acb\u8a08\u7b97 C<sub>1<\/sub>+C<sub>2<\/sub> +\u22ef+C<sub>N<\/sub> \u7684\u7e3d\u548c\u662f\u591a\u5c11\uff1f<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7bc4\u4f8b\u6e2c\u8cc7<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7bc4\u4f8b\u8f38\u5165<\/th><th>\u7bc4\u4f8b\u8f38\u51fa<\/th><\/tr><\/thead><tbody><tr><td>\u6e2c\u8a66\u8cc7\u6599\u7684\u8f38\u5165\u53ea\u6709\u5169\u5217\u3002<br>\u7b2c\u4e00\u5217\u70ba\u4e00\u500b\u6b63\u6574\u6578 N\uff0c\u8868\u793a\u8a72\u8857\u9053\u5171\u6709 N \u68df\u623f\u5b50\u3002<br>\u7b2c\u4e8c\u5217\u70ba N \u500b\u6b63\u6574\u6578 (H<sub>1<\/sub>, H<sub>2<\/sub>, .\u2026\uff0cH<sub>N<\/sub>\uff09\uff0c\u8868\u793a\u5f9e\u5de6\u81f3\u53f3\u6bcf\u4e00\u68df\u623f\u5b50\u7684\u9ad8\u5ea6\u3002<\/td><td><br>\u8acb\u8f38\u51fa\u4e00\u5217\uff0c\u5176\u4e2d\u5305\u542b\u4e00\u500b\u6574\u6578\uff0c\u8868\u793a\u8acb\u554f\u6bcf\u4e00\u68df\u623f\u5b50\u6240\u80fd\u770b\u898b\u7684\u5176\u4ed6\u623f\u5b50\u6578<br>\u91cf\u7e3d\u548c\u662f\u591a\u5c11\uff0c\u4e5f\u5373 C<sub>1<\/sub>+C<sub>2<\/sub>+\u22ef+C<sub>N<\/sub>\u3002<\/td><\/tr><tr><td>2<br>1 1<\/td><td>2<\/td><\/tr><tr><td>3<br>1 2 3<\/td><td>4<\/td><\/tr><tr><td>5<br>5 2 3 4 4<\/td><td>14<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">ZeroJudge A813 \u7bc4\u4f8b\u6e2c\u8cc7<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p>\u672c\u984c\u9700\u8981\u4f7f\u7528 Long Long Int \u4f86\u5b58\u8cc7\u6599\u3002<\/p>\n\n\n\n<p>\u5ba3\u544a\u4e00\u500b pair&lt;long long int, long long int> \u7684\u9663\u5217\uff0c\u9019\u500b\u6703\u662f\u4e00\u500b\u66ab\u5b58\u5340\uff0c\u5f9e\u5de6\u5230\u53f3\u548c\u53f3\u5230\u5de6\u770b\u7684\u539f\u7406\u662f\u4e00\u6a23\u7684\uff0c\u4ee5\u4e0b\u9019\u500b\u66ab\u5b58\u5340\u7c21\u7a31\u70ba Box\u3002<\/p>\n\n\n\n<p>\u6bcf\u4e00\u6b21\u8dd1\u5230\u4e00\u68df\u6a13\u6642\uff0c\u90fd\u8981\u5224\u65b7 Box \u88e1\u9762\u662f\u5426\u6709\u8cc7\u6599\uff0c\u5982\u679c\u6c92\u6709\u8cc7\u6599\u5c31\u5c07\u76ee\u524d\u7684\u6a13\u9ad8\u5ea6 push_back \u5230 Box \u4e2d\uff0c\u56e0\u70ba\u9663\u5217\u7684\u8cc7\u6599\u578b\u614b\u662f Pair\uff0cFirst \u6b04\u4f4d\u662f\u5b58\u6a13\u9ad8\u5ea6\uff0cSecond \u6b04\u4f4d\u662f\u5b58\u9023\u7e8c\u7684\u6642\u5019\u9019\u500b\u9ad8\u5ea6\u6709\u9023\u7e8c\u5e7e\u500b\u3002\u5982\u679c\u88e1\u9762\u5df2\u7d93\u6709\u8cc7\u6599\u4e86\u5c31\u8981\u8dd1\u4e00\u500b While \u8ff4\u5708\uff0c\u6bcf\u4e00\u6b21\u7684\u8ff4\u5708\u88e1\u8981\u9396\u5b9a Box \u7684\u6700\u5f8c\u4e00\u500b\u8cc7\u6599\uff0c\u7c21\u7a31 Last\u3002\u5982\u679c Last \u5927\u65bc\u76ee\u524d\u6a13\u9ad8\u5ea6\uff0c\u5c31\u4ee3\u8868\u5df2\u7d93\u4e0d\u80fd\u5f80\u524d\u4e86\uff0c\u5c07 ans++ \u4e4b\u5f8c\u5c31\u5c07 While \u8ff4\u5708 Break \u6389\u3002\u5982\u679c Last \u5c0f\u65bc\u76ee\u524d\u6a13\u9ad8\u5ea6\uff0c\u5247\u5c07 ans += Last.second\uff0c\u4e5f\u5c31\u662f\u6709\u5e7e\u500b\u9019\u500b\u9ad8\u5ea6\u7684\u6a13\u68df\uff0c\u4e26\u4e14\u5c07 Box \u505a pop_back\u3002\u5982\u679c Last \u7b49\u65bc\u76ee\u524d\u6a13\u9ad8\u5ea6\uff0c\u5247\u8981\u5148\u5c07 ans += Last.second\uff0c\u7136\u5f8c\u624d\u5c07 Last.second++\u3002\u4e26\u4e14\u5982\u679c Box \u4e2d\u9084\u6709\u5176\u4ed6\u7684\u8cc7\u6599\u5c31\u5c07 ans++\u3002\u5982\u679c\u662f\u7b49\u65bc\u7684\u60c5\u6cc1\u5c31\u4e0d\u9700\u8981\u5c07\u76ee\u524d\u6a13\u9ad8\u5ea6\u505a push_back\uff0c\u5176\u9918\u60c5\u6cc1\u90fd\u8981 push_back\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=a813\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge A813: \u57ce\u5e02\u89c0\u6e2c<\/a><\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>#include &lt;iostream&gt;\n#include &lt;vector&gt;\nusing namespace std;\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    int N;\n    vector&lt;long long int&gt;building;\n    vector&lt;pair&lt;long long int, long long int&gt;&gt;box;\n    cin &gt;&gt; N;\n    long long int ans = 0;\n    for (int i = 0; i&lt;N; i++) {\n        int tmp;\n        cin &gt;&gt; tmp;\n        building.push_back(tmp);\n        if (box.empty()) {\n            box.push_back(make_pair(tmp, 1));\n        }\n        else {\n            long long int count = 0;\n            bool push = true;\n            while (true) {\n                const int last = box.size()-1;\n                if (box.empty()) break;\n                if (box[last].first &gt; tmp) {\n                    count++;\n                    break;\n                }\n                if (box[last].first == tmp) {\n                    count += min(1, int(box.size()-1));\n                    count += box[last].second;\n                    box[last].second++;\n                    push = false;\n                    break;\n                }\n                if (box[last].first &lt; tmp) {\n                    count += box[last].second;\n                    box.pop_back();\n                }\n            }\n            if (push) box.push_back(make_pair(tmp, 1));\n            ans += count;\n        }\n    }\n    box.clear();\n    for (int i = N-1; i&gt;=0; i--) {\n        const int tmp = building[i];\n        if (box.empty()) {\n            box.push_back(make_pair(tmp, 1));\n        }\n        else {\n            long long int count = 0;\n            bool push = true;\n            while (true) {\n                const int last = box.size()-1;\n                if (box.empty()) break;\n                if (box[last].first &gt; tmp) {\n                    count++;\n                    break;\n                }\n                if (box[last].first == tmp) {\n                    count += box[last].second;\n                    count += min(1, int(box.size()-1));\n                    box[last].second++;\n                    push = false;\n                    break;\n                }\n                if (box[last].first &lt; tmp) {\n                    count += box[last].second;\n                    box.pop_back();\n                }\n            }\n            if (push) box.push_back(make_pair(tmp, 1));\n            ans += count;\n        }\n    }\n    cout &lt;&lt; ans &lt;&lt; &quot;\\n&quot;;\n}\n\n\/\/ZeroJudge A813\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u9ad8\u96c4\u5e02\u7684\u67d0\u8857\u9053\u4e0a\uff0c\u6709\u8a31\u591a\u9ad8\u77ee\u4e0d\u7b49\u7684\u623f\u5b50\u6392\u6210\u6574\u9f4a\u7684\u4e00\u5217\u3002 \u5c0d\u65bc\u5169\u68df\u4e0d\u540c\u7684\u623f\u5b50 A \u8207 B \u4f86\u8aaa\uff0c\u5982\u679c\u623f\u5b50 A  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","footnotes":""},"categories":[29],"tags":[15,20,8,34,9],"class_list":["post-1286","post","type-post","status-publish","format-standard","hentry","category-zerojudge-","tag-long-long-int","tag-20","tag-8","tag-34","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/comments?post=1286"}],"version-history":[{"count":1,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1286\/revisions"}],"predecessor-version":[{"id":1288,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1286\/revisions\/1288"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=1286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=1286"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=1286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}