{"id":176,"date":"2023-05-11T19:26:36","date_gmt":"2023-05-11T11:26:36","guid":{"rendered":"https:\/\/solost.cn\/?p=176"},"modified":"2023-05-11T19:26:36","modified_gmt":"2023-05-11T11:26:36","slug":"288","status":"publish","type":"post","link":"https:\/\/solost.cn\/?p=176","title":{"rendered":"Codeforces Round 872 (Div. 2) &#8211; C. LuoTianyi and the Show"},"content":{"rendered":"<h2>\u9898\u76ee\u94fe\u63a5<\/h2>\n<p><a href=\"https:\/\/codeforces.com\/contest\/1825\/problem\/C\">\u94fe\u63a5<\/a><\/p>\n<h2>\u9898\u76ee\u5927\u610f<\/h2>\n<p>\u9898\u76ee\u7684\u610f\u601d\u662f\u6709n\u4e2a\u4eba\uff0cm\u4e2a\u5ea7\u4f4d\uff0c\u6bcf\u4e2a\u4eba\u6709\u4e09\u79cd\u5ea7\u4f4d\u5750\u6cd5<\/p>\n<ol>\n<li>\u5982\u679c\u662f-1\u4ee3\u8868\u5750\u5728\u6700\u5de6\u8fb9\u4eba\u7684\u5de6\u8fb9\uff0c\u5982\u679c\u8fd8\u6ca1\u6709\u4eba\u5750\uff0c\u90a3\u5c31\u5750\u5728\u6700\u53f3\u8fb9m\u4f4d\u7f6e<\/li>\n<li>\u5982\u679c\u662f-2\u4ee3\u8868\u5750\u5728\u6700\u53f3\u8fb9\u4eba\u7684\u53f3\u8fb9\uff0c\u5982\u679c\u8fd8\u6ca1\u6709\u4eba\u5750\uff0c\u90a3\u5c31\u5750\u5728\u6700\u5de6\u8fb91\u4f4d\u7f6e<\/li>\n<li>\u5750\u5728x\u4f4d\u7f6e<\/li>\n<\/ol>\n<p>\u7136\u540e\u7ed9\u4f60\u4e00\u4e2a\u6570\u5217\u957f\u5ea6\u4e3an\uff0ca[i]\u53ea\u6709x,-1,-2\u8fd9\u4e24\u79cd\uff0c\u95ee\u4f60\u6700\u591a\u80fd\u5750\u591a\u5c11\u4e2a\u4eba<\/p>\n<h2>\u9898\u89e3<\/h2>\n<p>\u6211\u4eec\u4e0d\u59a8\u6765\u6362\u4e2a\u601d\u8def\uff0cx\u4f4d\u7f6e\u7684\u4eba\u53ea\u80fd\u5750\u5728x\u4f4d\u7f6e\uff0c\u4f46\u662f-1,-2\u53ef\u4ee5\u6309\u7167\u8981\u6c42\u5750\u5ea7\u4f4d\uff0c\u4e00\u4e2a\u4eba\u6709\u591a\u79cd\u5750\u6cd5\uff0c\u603b\u4f53\u601d\u8def\u5c31\u662f\u56fa\u5b9a\u5ea7\u4f4d\u7684\u4eba\u5750\u5728\u90a3\u4e2a\u4f4d\u7f6e\uff0c\u7136\u540e\u6765\u6309\u7167\u8981\u6c42\u586b\u5199-1\uff0c-2\u7684\u4eba\u3002\u7279\u4f8b\u60c5\u51b5\u5c31\u662f\u5148\u653e-1\uff0c-2\u7684\u60c5\u51b5\u5206\u522b\u8ba8\u8bba\u4ee5\u4e0b\u5c31\u884c\u4e86<\/p>\n<h2>\u4ee3\u7801<\/h2>\n<pre><code class=\"lang-cpp\">#include &lt;map&gt;\n#include &lt;set&gt;\n#include &lt;cmath&gt;\n#include &lt;queue&gt;\n#include &lt;stack&gt;\n#include &lt;vector&gt;\n#include &lt;bitset&gt;\n#include &lt;cstdio&gt;\n#include &lt;cstdlib&gt;\n#include &lt;cstring&gt;\n#include &lt;fstream&gt;\n#include &lt;iostream&gt;\n#include &lt;algorithm&gt;\n#include &lt;unordered_map&gt;\n#include &lt;unordered_set&gt;\n\n#define x first\n#define y second\n#define endl &#039;\\n&#039;\n#define IOS                       \\\n    ios_base::sync_with_stdio(0); \\\n    cin.tie(0);                   \\\n    cout.tie(0);\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef pair&lt;ll, ll&gt; pll;\ntypedef pair&lt;int, int&gt; pii;\ntypedef unsigned long long ull;\n\nconst int INF = 0x3f3f3f3f, mod = 1000000007;\nconst int N = 2e5 + 10;\nint s[N];\nvoid solve()\n{\n    int n, m;\n    cin &gt;&gt; n &gt;&gt; m;\n    map&lt;int, int&gt; a;\n    memset(s, 0, sizeof s);\n    set&lt;int&gt; q;\n    for(int i = 1; i &lt;= n; i++){\n        int x;\n        cin &gt;&gt; x;\n        if(x &gt; 0){\n            s[x] = 1;\n            q.insert(x);\n        }\n        a[x]++;\n    }\n    for(int i = 1; i &lt;= m; i++){\n        s[i] += s[i - 1];\n    }\n    int ans = 0;\n    if(a[-1]){\n        ans = max(ans, min(m, s[m - 1] + a[-1]));\n        \/\/ cout &lt;&lt; ans &lt;&lt; endl;\n    }\n    if(a[-2]){\n        ans = max(ans, min(m, s[m] - s[1] + a[-2]));\n        \/\/ cout &lt;&lt; ans &lt;&lt; endl;\n    }\n    for(auto x : q){\n        ans = max(ans, 1 + min(x - 1, s[x - 1] + a[-1]) + min(m - x, s[m] - s[x] + a[-2]));\n    }\n    cout &lt;&lt; ans &lt;&lt; endl;\n}\nint main()\n{\n    IOS;\n    int t = 1;\n    cin &gt;&gt; t;\n    while (t--) {\n        solve();\n    }\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee\u94fe\u63a5 \u94fe\u63a5 \u9898\u76ee\u5927\u610f \u9898\u76ee\u7684\u610f\u601d\u662f\u6709n\u4e2a\u4eba\uff0cm\u4e2a\u5ea7\u4f4d\uff0c\u6bcf\u4e2a\u4eba\u6709\u4e09\u79cd\u5ea7\u4f4d\u5750\u6cd5 \u5982\u679c\u662f-1\u4ee3\u8868\u5750\u5728\u6700\u5de6\u8fb9\u4eba\u7684\u5de6\u8fb9\uff0c\u5982\u679c\u8fd8\u6ca1\u6709\u4eba\u5750\uff0c\u90a3\u5c31\u5750\u5728\u6700\u53f3\u8fb9m\u4f4d\u7f6e \u5982\u679c\u662f-2\u4ee3\u8868\u5750\u5728\u6700\u53f3\u8fb9\u4eba\u7684\u53f3\u8fb9\uff0c\u5982\u679c\u8fd8\u6ca1\u6709\u4eba\u5750\uff0c\u90a3\u5c31\u5750\u5728\u6700\u5de6\u8fb91\u4f4d\u7f6e \u5750\u5728x\u4f4d\u7f6e \u7136\u540e\u7ed9\u4f60\u4e00\u4e2a\u6570\u5217\u957f\u5ea6\u4e3an\uff0ca[i]\u53ea\u6709x,-1,-2\u8fd9\u4e24\u79cd\uff0c\u95ee\u4f60\u6700\u591a\u80fd\u5750\u591a\u5c11\u4e2a\u4eba \u9898\u89e3 \u6211\u4eec\u4e0d\u59a8\u6765\u6362\u4e2a\u601d\u8def\uff0cx\u4f4d\u7f6e\u7684\u4eba\u53ea\u80fd\u5750\u5728x\u4f4d\u7f6e\uff0c\u4f46\u662f-1,-2\u53ef\u4ee5\u6309\u7167\u8981\u6c42\u5750\u5ea7\u4f4d\uff0c\u4e00\u4e2a\u4eba\u6709\u591a\u79cd\u5750\u6cd5\uff0c\u603b\u4f53\u601d\u8def\u5c31\u662f\u56fa\u5b9a\u5ea7\u4f4d\u7684\u4eba\u5750\u5728\u90a3\u4e2a\u4f4d\u7f6e\uff0c\u7136\u540e\u6765\u6309\u7167\u8981\u6c42\u586b\u5199-1\uff0c-2\u7684\u4eba\u3002\u7279\u4f8b\u60c5\u51b5\u5c31\u662f\u5148\u653e-1\uff0c-2\u7684\u60c5\u51b5\u5206\u522b\u8ba8\u8bba\u4ee5\u4e0b\u5c31\u884c\u4e86 \u4ee3\u7801 #include &lt;map&gt; #include &lt;set&gt; #include &lt;cmath&gt; #include &lt;queue&gt; #include &lt;stack&gt; #include &lt;vector&gt; #include &lt;bitset&gt; #include &lt;cstdio&gt; #include &lt;cstdlib&gt; #include &lt;cstring&gt; #include &lt;fstream&gt; #include &lt;iostream&gt; #include &lt;algorithm&gt; #include &lt;unordered_map&gt; #include &lt;unordered_set&gt; #define x first #define y second #define endl &#039;\\n&#039; #define IOS \\ ios_base::sync_with_stdio(0); \\ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[5,7],"class_list":["post-176","post","type-post","status-publish","format-standard","hentry","category-solution","tag-5","tag-7"],"_links":{"self":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/176","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=176"}],"version-history":[{"count":0,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/176\/revisions"}],"wp:attachment":[{"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}