{"id":1367,"date":"2024-02-07T00:13:00","date_gmt":"2024-02-06T16:13:00","guid":{"rendered":"http:\/\/www.forillusion.com\/?p=1367"},"modified":"2025-02-14T11:39:10","modified_gmt":"2025-02-14T03:39:10","slug":"training-report-on-the-third-week-of-winter-vacation-training","status":"publish","type":"post","link":"https:\/\/www.forillusion.com\/index.php\/training-report-on-the-third-week-of-winter-vacation-training\/","title":{"rendered":"\u5bd2\u5047\u8bad\u7ec3\u7b2c\u4e09\u5468\u8bad\u7ec3\u62a5\u544a"},"content":{"rendered":"\n<p><div class=\"has-toc have-toc\"><\/div><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Part 1.\u7b14\u8bb0<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u5355\u8c03\u6808<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">\u6a21\u7248<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u4ee5\u4e0b\u6240\u6709\u5c06b&#91;i]=q.top().second\u6539\u4e3ab&#91;i]=q.top().first \u5373\u53ef\u5f97\u5230\u5143\u7d20\u7684\u503c\u800c\u4e0d\u662f\u5750\u6807\u3002\n\/\/n\u4e3a\u6570\u7ec4\u89c4\u6a21\uff0c\u9ed8\u8ba4\u4e0b\u6807\u4ece1\u5f00\u59cb\n\/\/\u6570\u7ec4a\u4e3a\u539f\u6570\u7ec4\n\/\/\u6570\u7ec4b\u4e3a\u67e5\u627e\u5230\u7684\u5750\u6807\uff08\u5143\u7d20\u503c\uff09\nvoid findRMin(int n,int a&#91;],int b&#91;])   \/\/\u5bfb\u627e\u53f3\u8fb9\u7b2c\u4e00\u4e2a\u6bd4\u81ea\u5df1\u5c0f\u7684\u5143\u7d20\u7684\u5750\u6807\n{\n    stack&lt;pair&lt;int,int&gt;&gt; q;\n    for (int i=n;i&gt;=1;i--)\n    {\n        while (!q.empty()&amp;&amp;a&#91;i]&lt;=q.top().first)\n            q.pop();\n        if (q.empty()) b&#91;i]=0;\n        else b&#91;i]=q.top().second;\n        q.push(make_pair(a&#91;i],i));\n    }\n}\n\nvoid findLMin(int n,int a&#91;],int b&#91;])   \/\/\u5bfb\u627e\u5de6\u8fb9\u7b2c\u4e00\u4e2a\u6bd4\u81ea\u5df1\u5c0f\u7684\u5143\u7d20\u7684\u5750\u6807\n{\n    stack&lt;pair&lt;int,int&gt;&gt; q;\n    for (int i=1;i&lt;=n;i++)\n    {\n        while (!q.empty()&amp;&amp;a&#91;i]&lt;=q.top().first)\n            q.pop();\n        if (q.empty()) b&#91;i]=0;\n        else b&#91;i]=q.top().second;\n        q.push(make_pair(a&#91;i],i));\n    }\n}\n\nvoid findRMax(int n,int a&#91;],int b&#91;])   \/\/\u5bfb\u627e\u53f3\u8fb9\u7b2c\u4e00\u4e2a\u6bd4\u81ea\u5df1\u5927\u7684\u5143\u7d20\u7684\u5750\u6807\n{\n    stack&lt;pair&lt;int,int&gt;&gt; q;\n    for (int i=n;i&gt;=1;i--)\n    {\n        while (!q.empty()&amp;&amp;a&#91;i]&gt;=q.top().first)\n            q.pop();\n        if (q.empty()) b&#91;i]=0;\n        else b&#91;i]=q.top().second;\n        q.push(make_pair(a&#91;i],i));\n    }\n}\n\nvoid findLMax(int n,int a&#91;],int b&#91;])   \/\/\u5bfb\u627e\u5de6\u8fb9\u7b2c\u4e00\u4e2a\u6bd4\u81ea\u5df1\u5927\u7684\u5143\u7d20\u7684\u5750\u6807\n{\n    stack&lt;pair&lt;int,int&gt;&gt; q;\n    for (int i=1;i&lt;=n;i++)\n    {\n        while (!q.empty()&amp;&amp;a&#91;i]&gt;=q.top().first)\n            q.pop();\n        if (q.empty()) b&#91;i]=0;\n        else b&#91;i]=q.top().second;\n        q.push(make_pair(a&#91;i],i));\n    }\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u89e3\u91ca<\/h4>\n\n\n\n<p>\u4ee5\u5bfb\u627e\u53f3\u8fb9\u7b2c\u4e00\u4e2a\u6bd4\u81ea\u5df1\u5c0f\u7684\u5143\u7d20\u7684\u5750\u6807\u4e3a\u4f8b\uff0c\u4ece\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u5f00\u59cb\u4ece\u53f3\u5f80\u5de6\u904d\u5386\uff0c\u6808q\u4e2d\u6309\u7167\u4ece\u9876\u5230\u5e95\u964d\u5e8f\u5b58\u50a8\u3002<br>\u7b2c\u4e00\u4e2awhile\u5faa\u73af\u4f1a\u5f39\u51fa\u6808\u4e2d\u6240\u6709\u5927\u4e8e\u5f53\u524d\u5143\u7d20a[i]\u7684\u5143\u7d20\uff0c\u76f4\u5230\u627e\u5230\u6bd4\u81ea\u5df1\u8fd8\u5c0f\u7684\u5143\u7d20\uff0c\u8fd9\u4f7f\u5f97\u6808\u4e2d\u7684\u6240\u6709\u5143\u7d20\u90fd\u6bd4a[i]\u5c0f\u3002<br>\u88ab\u5f39\u51fa\u5143\u7d20\u56e0\u4e3a\u5176\u5927\u4e8e\u5f53\u524d\u5143\u7d20a[i]\uff0c\u6240\u4ee5\u5bf9\u4e8ea[i]\u5de6\u8fb9\u7684\u5143\u7d20\u6765\u8bf4\uff0c\u88ab\u5f39\u51fa\u5143\u7d20\u4e0d\u53ef\u80fd\u4e3a\u7b2c\u4e00\u4e2a\u5c0f\u4e8e\u7684\u5143\u7d20\uff0c\u6240\u4ee5\u88ab\u5f39\u51fa\u3002<br>\u968f\u540e\u6839\u636e\u6808\u4e2d\u662f\u5426\u6709\u5143\u7d20\u6765\u5224\u65ad\u53f3\u8fb9\u662f\u5426\u6709\u5143\u7d20\u5c0f\u4e8e\u5b83\uff0c\u5982\u679c\u4e3a\u7a7a\u5219\u6ca1\u6709\uff0c\u4e0d\u4e3a\u7a7a\u5219\u6808\u9876\u7aef\u7684\u5143\u7d20\u662f\u7b2c\u4e00\u4e2a\u5c0f\u4e8e\u5b83\u7684\u5143\u7d20\u3002<br>\u968f\u540e\u5c06\u5143\u7d20a[i]\u548c\u5750\u6807i\u538b\u5165\u6808\u4e2d\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b57\u5178\u6811Trie Tree<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">\u6a21\u7248<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>struct trie\n{\n    int next&#91;26];   \/\/\u6307\u5411\u5b50\u8282\u70b9\u8282\u70b9\u7684\u4e0b\u6807\uff0c\u9ed8\u8ba4\u503c\u4e3a0\u5219\u8868\u793a\u6ca1\u6709\u5b50\u8282\u70b9\uff0c\u5e76\u75280-25\u4ee3\u8868'a'-'z'\n    int isEnd;   \/\/\u662f\u5426\u4e3a\u4e00\u4e2a\u5355\u8bcd\u7684\u7ed3\u5c3e\n}tree&#91;500005];\nint inc;   \/\/\u6700\u540e\u4e00\u4e2a\u5206\u914d\u7684\u5b57\u5178\u6811\u4e0b\u6807\uff0c\u7528\u4e8e\u5206\u914d\u65b0\u7684\u8282\u70b9\u4e0b\u6807\n\nint insert(string s)   \/\/\u63d2\u5165\u5355\u8bcd\n{\n    int p=0;   \/\/\u4e34\u65f6\u6307\u9488\uff0c\u6307\u5411\u5b50\u8282\u70b9\uff0c\u521d\u59cb\u6307\u54110\uff0c\u5373\u6811\u7684\u6839\n    for (int i=0;i&lt;s.size();i++)   \/\/\u904d\u5386\u5355\u8bcd\u7684\u6bcf\u4e00\u4e2a\u5b57\u7b26\n    {\n        if (tree&#91;p].next&#91;s&#91;i]-97]) p=tree&#91;p].next&#91;s&#91;i]-97];    \/\/\u5982\u679c\u5f53\u524d\u8282\u70b9\u5b58\u5728\u5b57\u6bcd\u4e3as&#91;i]\u7684\u5b50\u8282\u70b9\uff0c\u5219\u5c06p\u6307\u5411\u8be5\u5b50\u8282\u70b9\n        else   \/\/\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5219\u521b\u5efa\u8be5\u8282\u70b9\n        {\n            inc++;   \/\/\u5206\u914d\u65b0\u7684\u4e0b\u6807\n            tree&#91;p].next&#91;s&#91;i]-97]=inc;   \/\/\u5c06\u5f53\u524d\u8282\u70b9\u5b57\u6bcd\u4e3as&#91;i]\u7684\u5b50\u8282\u70b9\u6307\u5411\u65b0\u8282\u70b9\n            p=inc;   \/\/\u5c06\u4e34\u65f6\u6307\u9488\u6307\u5411\u65b0\u8282\u70b9\n        }\n    }\n    if (tree&#91;p].isEnd) return 1;   \/\/\u904d\u5386\u5b8c\u5355\u8bcd\u540e\uff0c\u6307\u9488p\u5c06\u6307\u5411\u5355\u8bcd\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u6240\u5728\u7684\u8282\u70b9\uff0c\u5224\u65ad\u8be5\u8282\u70b9\u7684\u5355\u8bcd\u672b\u5c3e\u6807\u8bb0\u662f\u5426\u4e3a1\uff0c\u5982\u679c\u662f\u5219\u8bf4\u660e\u4e4b\u524d\u6dfb\u52a0\u8fc7\u8be5\u5355\u8bcd\u4e86\uff0c\u8fd4\u56de1\u3002\n    else tree&#91;p].isEnd=1;   \/\/\u5426\u5219\u8bf4\u660e\u4e4b\u524d\u6ca1\u6dfb\u52a0\u8fc7\u8be5\u5355\u8bcd\uff0c\u5c06\u5176\u7684\u5355\u8bcd\u672b\u5c3e\u6807\u8bb0\u7f6e\u4e3a1\uff0c\u7136\u540e\u8fd4\u56de0\u3002\n    return 0;\n}\n\nint check(string s)   \/\/\u68c0\u67e5\u5355\u8bcd\u662f\u5426\u5b58\u5728\n{\n    int p=0;   \/\/\u4e34\u65f6\u6307\u9488\uff0c\u6307\u5411\u5b50\u8282\u70b9\uff0c\u521d\u59cb\u6307\u54110\uff0c\u5373\u6811\u7684\u6839\n    for (int i=0;i&lt;s.size();i++)   \/\/\u904d\u5386\u5355\u8bcd\u7684\u6bcf\u4e00\u4e2a\u5b57\u7b26\n    {\n        if (!tree&#91;p].next&#91;s&#91;i]-97]) return 0;   \/\/\u5982\u679c\u5f53\u524d\u8282\u70b9\u4e0d\u5b58\u5728\u5b57\u6bcd\u4e3as&#91;i]\u7684\u5b50\u8282\u70b9\uff0c\u5219\u8868\u793a\u8be5\u5355\u8bcd\u4e0d\u5b58\u5728\uff0c\u8fd4\u56de0\n        p=tree&#91;p].next&#91;s&#91;i]-97];   \/\/\u5c06\u4e34\u65f6\u6307\u9488\u6307\u5411\u5b57\u6bcd\u4e3as&#91;i]\u7684\u5b50\u8282\u70b9\n    }\n    if (tree&#91;p].isEnd) return 1;   \/\/\u904d\u5386\u5b8c\u5355\u8bcd\u540e\uff0c\u6307\u9488p\u5c06\u6307\u5411\u5355\u8bcd\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u6240\u5728\u7684\u8282\u70b9\uff0c\u5224\u65ad\u8be5\u8282\u70b9\u7684\u5355\u8bcd\u672b\u5c3e\u6807\u8bb0\u662f\u5426\u4e3a1\uff0c\u5982\u679c\u662f\u5219\u8bf4\u660e\u8be5\u5355\u8bcd\u5b58\u5728\uff0c\u8fd4\u56de1\uff0c\u5426\u5219\u8fd4\u56de0\u3002\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u89e3\u91ca<\/h4>\n\n\n\n<p>\u5b57\u5178\u6811\uff0c\u662f\u4e00\u79cd<strong>\u7a7a\u95f4\u6362\u65f6\u95f4<\/strong>\u7684\u6570\u636e\u7ed3\u6784\uff0c\u53c8\u79f0Trie\u6811\u3001\u524d\u7f00\u6811\uff0c\u662f\u4e00\u79cd\u6811\u5f62\u7ed3\u6784\uff0c\u5178\u578b\u7528\u4e8e\u7edf\u8ba1\u3001\u6392\u5e8f\u3001\u548c\u4fdd\u5b58\u5927\u91cf\u5b57\u7b26\u4e32\u3002\u5229\u7528\u5b57\u7b26\u4e32\u7684\u516c\u5171\u524d\u7f00\u6765\u51cf\u5c11\u67e5\u8be2\u65f6\u95f4\uff0c\u6700\u5927\u9650\u5ea6\u5730\u51cf\u5c11\u4e0d\u9700\u8981\u7684\u5b57\u7b26\u4e32\u6bd4\u8f83\uff0c\u67e5\u8be2\u6548\u7387\u6bd4\u54c8\u5e0c\u6811\u9ad8\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/pic1.zhimg.com\/80\/v2-c6c00f279fb8a978ba6a7b08820e92e8_720w.webp\" src=\"https:\/\/cdn.forillusion.com\/moezx\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\" width=\"479\" height=\"332\"\/><\/figure >\n<noscript><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/pic1.zhimg.com\/80\/v2-c6c00f279fb8a978ba6a7b08820e92e8_720w.webp\" alt=\"\" width=\"479\" height=\"332\"\/><\/figure><\/noscript>\n\n\n\n<p>\u6839\u8282\u70b9\u4e0d\u5305\u542b\u5b57\u7b26\uff0c\u9664\u6839\u8282\u70b9\u5916\u6bcf\u4e00\u4e2a\u8282\u70b9\u90fd\u53ea\u5305\u542b\u4e00\u4e2a\u5b57\u7b26\u3002<br>\u4ece\u6839\u8282\u70b9\u5230\u67d0\u4e00\u8282\u70b9\uff0c\u8def\u5f84\u4e0a\u7ecf\u8fc7\u7684\u5b57\u7b26\u8fde\u63a5\u8d77\u6765\uff0c\u4e3a\u8be5\u8282\u70b9\u5bf9\u5e94\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n\n\n\n<p>\u5b9a\u4e49\u7ed3\u6784\u4f53\uff1a\u8be5\u7ed3\u6784\u4f53\u7528\u6765\u5b58\u50a8\u6811\u7684\u6bcf\u4e00\u4e2a\u8282\u70b9\uff0c\u6bcf\u4e2a\u8282\u70b9\u90fd\u5305\u62ec\u4e86\u6307\u5411\u5b50\u8282\u70b9\u7684\u6307\u9488\uff0c\u4ee5\u53ca\u5f53\u524d\u8282\u70b9\u662f\u5426\u4e3a\u5355\u8bcd\u7684\u7ed3\u5c3e\u3002<br>\u7528\u6570\u7ec4\u7ebf\u6027\u5b58\u50a8\u6811\uff0c\u6240\u4ee5\u6307\u9488\u8bb0\u5f55\u7684\u662f\u5b50\u8282\u70b9\u7684\u6570\u7ec4\u4e0b\u6807\u503c\u3002<br>inc\u8bb0\u5f55\u7684\u662f\u5f53\u524d\u7684\u6570\u7ec4\u4e0b\u6807\u5df2\u7ecf\u5206\u914d\u5230\u591a\u5c11\u4e86\uff0c\u7528\u4e8e\u5206\u914d\u65b0\u7684\u8282\u70b9\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>struct trie\n{\n    int next&#91;26];   \/\/\u6307\u5411\u5b50\u8282\u70b9\u8282\u70b9\u7684\u4e0b\u6807\uff0c\u9ed8\u8ba4\u503c\u4e3a0\u5219\u8868\u793a\u6ca1\u6709\u5b50\u8282\u70b9\uff0c\u5e76\u75280-25\u4ee3\u8868'a'-'z'\n    int isEnd;   \/\/\u662f\u5426\u4e3a\u4e00\u4e2a\u5355\u8bcd\u7684\u7ed3\u5c3e\n}tree&#91;500005];\nint inc;   \/\/\u6700\u540e\u4e00\u4e2a\u5206\u914d\u7684\u5b57\u5178\u6811\u4e0b\u6807\uff0c\u7528\u4e8e\u5206\u914d\u65b0\u7684\u8282\u70b9\u4e0b\u6807<\/code><\/pre>\n\n\n\n<p>\u63d2\u5165\u5355\u8bcd\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"cpp\">int insert(string s)   \/\/\u63d2\u5165\u5355\u8bcd\n{\n    int p=0;   \/\/\u4e34\u65f6\u6307\u9488\uff0c\u6307\u5411\u5b50\u8282\u70b9\uff0c\u521d\u59cb\u6307\u54110\uff0c\u5373\u6811\u7684\u6839\n    for (int i=0;i&lt;s.size();i++)   \/\/\u904d\u5386\u5355\u8bcd\u7684\u6bcf\u4e00\u4e2a\u5b57\u7b26\n    {\n        if (tree&#91;p].next&#91;s&#91;i]-97]) p=tree&#91;p].next&#91;s&#91;i]-97];    \/\/\u5982\u679c\u5f53\u524d\u8282\u70b9\u5b58\u5728\u5b57\u6bcd\u4e3as&#91;i]\u7684\u5b50\u8282\u70b9\uff0c\u5219\u5c06p\u6307\u5411\u8be5\u5b50\u8282\u70b9\n        else   \/\/\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5219\u521b\u5efa\u8be5\u8282\u70b9\n        {\n            inc++;   \/\/\u5206\u914d\u65b0\u7684\u4e0b\u6807\n            tree&#91;p].next&#91;s&#91;i]-97]=inc;   \/\/\u5c06\u5f53\u524d\u8282\u70b9\u5b57\u6bcd\u4e3as&#91;i]\u7684\u5b50\u8282\u70b9\u6307\u5411\u65b0\u8282\u70b9\n            p=inc;   \/\/\u5c06\u4e34\u65f6\u6307\u9488\u6307\u5411\u65b0\u8282\u70b9\n        }\n    }\n    if (tree&#91;p].isEnd) return 1;   \/\/\u904d\u5386\u5b8c\u5355\u8bcd\u540e\uff0c\u6307\u9488p\u5c06\u6307\u5411\u5355\u8bcd\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u6240\u5728\u7684\u8282\u70b9\uff0c\u5224\u65ad\u8be5\u8282\u70b9\u7684\u5355\u8bcd\u672b\u5c3e\u6807\u8bb0\u662f\u5426\u4e3a1\uff0c\u5982\u679c\u662f\u5219\u8bf4\u660e\u4e4b\u524d\u6dfb\u52a0\u8fc7\u8be5\u5355\u8bcd\u4e86\uff0c\u8fd4\u56de1\u3002\n    else tree&#91;p].isEnd=1;   \/\/\u5426\u5219\u8bf4\u660e\u4e4b\u524d\u6ca1\u6dfb\u52a0\u8fc7\u8be5\u5355\u8bcd\uff0c\u5c06\u5176\u7684\u5355\u8bcd\u672b\u5c3e\u6807\u8bb0\u7f6e\u4e3a1\uff0c\u7136\u540e\u8fd4\u56de0\u3002\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p>\u68c0\u67e5\u5355\u8bcd\u662f\u5426\u5b58\u5728\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"cpp\">int check(string s)   \/\/\u68c0\u67e5\u5355\u8bcd\u662f\u5426\u5b58\u5728\n{\n    int p=0;   \/\/\u4e34\u65f6\u6307\u9488\uff0c\u6307\u5411\u5b50\u8282\u70b9\uff0c\u521d\u59cb\u6307\u54110\uff0c\u5373\u6811\u7684\u6839\n    for (int i=0;i&lt;s.size();i++)   \/\/\u904d\u5386\u5355\u8bcd\u7684\u6bcf\u4e00\u4e2a\u5b57\u7b26\n    {\n        if (!tree&#91;p].next&#91;s&#91;i]-97]) return 0;   \/\/\u5982\u679c\u5f53\u524d\u8282\u70b9\u4e0d\u5b58\u5728\u5b57\u6bcd\u4e3as&#91;i]\u7684\u5b50\u8282\u70b9\uff0c\u5219\u8868\u793a\u8be5\u5355\u8bcd\u4e0d\u5b58\u5728\uff0c\u8fd4\u56de0\n        p=tree&#91;p].next&#91;s&#91;i]-97];   \/\/\u5c06\u4e34\u65f6\u6307\u9488\u6307\u5411\u5b57\u6bcd\u4e3as&#91;i]\u7684\u5b50\u8282\u70b9\n    }\n    if (tree&#91;p].isEnd) return 1;   \/\/\u904d\u5386\u5b8c\u5355\u8bcd\u540e\uff0c\u6307\u9488p\u5c06\u6307\u5411\u5355\u8bcd\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u6240\u5728\u7684\u8282\u70b9\uff0c\u5224\u65ad\u8be5\u8282\u70b9\u7684\u5355\u8bcd\u672b\u5c3e\u6807\u8bb0\u662f\u5426\u4e3a1\uff0c\u5982\u679c\u662f\u5219\u8bf4\u660e\u8be5\u5355\u8bcd\u5b58\u5728\uff0c\u8fd4\u56de1\uff0c\u5426\u5219\u8fd4\u56de0\u3002\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5e76\u67e5\u96c6<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">\u6a21\u7248<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;bits\/stdc++.h&gt;\nusing namespace std;\nint n,m,k,x,y;\nint pre&#91;200005];\n\nint find(int x)\n   \/\/\u67e5\u627e\u6839\n{\n    if (x!=pre&#91;x]) pre&#91;x]=find(pre&#91;x]);\n    return pre&#91;x];\n}\n\nvoid merge(int a,int b)\n   \/\/\u5408\u5e76\n{\n    int x=find(a);\n    int y=find(b);\n    pre&#91;x]=y;\n}\n\nint main()\n{\n    cin&gt;&gt;n&gt;&gt;m;\n    for (int i=1;i&lt;=n;i++)\n        pre&#91;i]=i;\n    for (int i=1;i&lt;=m;i++)\n    {\n        cin&gt;&gt;k&gt;&gt;x&gt;&gt;y;\n        if (k==1) merge(x,y);\n        if (k==2) \n        {\n            int x0=find(x);\n            int y0=find(y);\n            if (x0==y0) cout&lt;&lt;\"Y\"&lt;&lt;endl;\n            else cout&lt;&lt;\"N\"&lt;&lt;endl;\n        }\n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u89e3\u91ca<\/h4>\n\n\n\n<p>\u5e76\u67e5\u96c6\u662f\u53ef\u4ee5\u5feb\u901f\u5b8c\u6210\u5224\u65ad\u4e24\u4e2a\u5143\u7d20\u662f\u5426\u5728\u540c\u4e00\u96c6\u5408\u6216\u8005\u5408\u5e76\u4e24\u4e2a\u96c6\u5408\u7684\u4e00\u79cd\u6570\u636e\u7ed3\u6784\u3002<\/p>\n\n\n\n<p>\u5c06\u6bcf\u4e00\u4e2a\u5143\u7d20\u90fd\u89c6\u4e3a\u6811\u4e0a\u7684\u4e00\u4e2a\u8282\u70b9\uff0c\u6bcf\u4e00\u4e2a\u96c6\u5408\u5c31\u662f\u4e00\u68f5\u72ec\u7acb\u7684\u6811\uff0c\u6307\u5b9a\u4e00\u4e2a\u96c6\u5408\u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\u5143\u7d20\u4e3a\u6839\uff0c\u5c06\u5176\u4ed6\u5143\u7d20\u4ee5\u6811\u7684\u5f62\u5f0f\u8fde\u63a5\u5230\u8fd9\u4e2a\u6839\u4e0a\u3002\u540c\u65f6\u6811\u4e2d\u7684\u6bcf\u4e00\u4e2a\u8282\u70b9\u90fd\u5b58\u50a8\u7740\u4e00\u4e2a\u6307\u9488\u6307\u5411\u4ed6\u7684\u7236\u8282\u70b9\u3002\u800c\u6839\u8282\u70b9\u7684\u7236\u8282\u70b9\u6307\u5411\u81ea\u5df1\u3002<\/p>\n\n\n\n<p>\u5e76\u67e5\u96c6\u6709\u4e24\u79cd\u57fa\u7840\u64cd\u4f5c\uff0c\u67e5\u627e\u6839\u548c\u5408\u5e76\u96c6\u5408\u3002<\/p>\n\n\n\n<p>\u67e5\u627e\u4e00\u4e2a\u5143\u7d20\u7684\u6839\u65f6\uff0c\u56e0\u4e3a\u6bcf\u4e00\u4e2a\u5143\u7d20\u5c31\u662f\u6811\u4e0a\u7684\u4e00\u4e2a\u8282\u70b9\uff0c\u800c\u8282\u70b9\u8bb0\u5f55\u7740\u81ea\u5df1\u7684\u7236\u8282\u70b9\uff0c\u6240\u4ee5\u53ef\u4ee5\u5229\u7528\u9012\u5f52\u987a\u7740\u8bb0\u5f55\u7684\u7236\u8282\u70b9\u4e0d\u65ad\u5411\u4e0a\u67e5\u627e\uff0c\u76f4\u5230\u627e\u5230\u4e00\u4e2a\u8282\u70b9\u5176\u7236\u8282\u70b9\u5c31\u662f\u4ed6\u81ea\u5df1\uff0c\u8fd9\u4e2a\u8282\u70b9\u5c31\u662f\u6839\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int find(int x)   \/\/\u67e5\u627e\u6839\n{\n    if (x!=pre&#91;x]) return find(pre&#91;x]);\n    else return x;\n}<\/code><\/pre>\n\n\n\n<p>\u800c\u5408\u5e76\u4e24\u4e2a\u96c6\u5408\u65f6\uff0c\u4e5f\u5c31\u662f\u9700\u8981\u5c06\u5176\u4e2d\u4e00\u4e2a\u96c6\u5408\u7684\u6811\u8fde\u63a5\u5230\u5230\u53e6\u4e00\u4e2a\u96c6\u5408\u7684\u6811\u4e0a\uff0c\u4e8e\u662f\u67e5\u627e\u5230\u5176\u4e2d\u4e00\u4e2a\u6811\u7684\u6839\uff0c\u5e76\u5c06\u8fd9\u4e2a\u6839\u7684\u7236\u8282\u70b9\u6307\u5411\u53e6\u4e00\u4e2a\u6811\u4e0a\u7684\u4efb\u610f\u5143\u7d20\u3002<\/p>\n\n\n\n<p>\u4e5f\u5c31\u662f\u8bf4\uff0c\u5408\u5e76\u96c6\u5408\u662f\u5728\u67e5\u627e\u6839\u7684\u57fa\u7840\u4e0a\u5b8c\u6210\u7684\u3002\u800c\u67e5\u627e\u6839\u65f6\uff0c\u9012\u5f52\u7684\u6df1\u5ea6\u662f\u7531\u5f53\u524d\u8282\u70b9\u5230\u6811\u6839\u7684\u8ddd\u79bb\u51b3\u5b9a\u7684\uff0c\u800c\u5e76\u4e0d\u5173\u7cfb\u9014\u4e2d\u7ecf\u8fc7\u4e86\u54ea\u4e9b\u8282\u70b9\uff0c\u5373\u8282\u70b9\u8ddd\u79bb\u6811\u6839\u8d8a\u8fd1\uff0c\u9012\u5f52\u6df1\u5ea6\u8d8a\u4f4e\u3002\u90a3\u4e48\u5c06\u6bcf\u4e00\u4e2a\u8282\u70b9\u90fd\u76f4\u63a5\u8fde\u63a5\u5728\u6811\u6839\u4e0a\uff0c\u8fd9\u662f\u67e5\u627e\u6811\u6839\u7684\u901f\u5ea6\u5c06\u662f\u6700\u5feb\u7684\u3002\u4e8e\u662f\u5728\u8fdb\u884c\u5408\u5e76\u64cd\u4f5c\u65f6\uff0c\u4f1a\u540c\u65f6\u627e\u5230\u8981\u5408\u5e76\u7684\u4e24\u68f5\u6811\u7684\u6839\uff0c\u5e76\u5c06\u5176\u4e2d\u7684\u4e00\u4e2a\u6839\u7684\u7236\u8282\u70b9\u76f4\u63a5\u6307\u5411\u53e6\u4e00\u4e2a\u6839\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"cpp\">void merge(int a,int b)\n   \/\/\u5408\u5e76\n{\n    int x=find(a);\n    int y=find(b);\n    pre&#91;x]=y;\n}<\/code><\/pre>\n\n\n\n<p>\u4f46\u8fd9\u6837\u505a\u5e76\u4e0d\u662f\u6700\u5feb\u7684\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7<strong>\u8def\u5f84\u538b\u7f29<\/strong>\u4f7f\u5f97\u64cd\u4f5c\u66f4\u5feb\u4e00\u70b9\u3002\u5728\u5229\u7528\u9012\u5f52\u67e5\u627e\u6839\u7684\u540c\u65f6\uff0c\u5f53\u627e\u5230\u6839\u540e\uff0c\u6839\u7684\u4e0b\u6807\u4f1a\u88ab\u4e00\u8def\u4ee5\u8fd4\u56de\u7ed9\u4e0a\u4e00\u5c42\u51fd\u6570\uff0c\u5373\u67e5\u627e\u8fc7\u7a0b\u4e2d\u7ecf\u8fc7\u7684\u5b50\u8282\u70b9\uff0c\u8fd9\u662f\u5c31\u53ef\u4ee5\u5c06\u9014\u7ecf\u7684\u6240\u6709\u8282\u70b9\u7684\u7236\u8282\u70b9\u90fd\u6307\u5411\u6839\uff0c\u4e5f\u5c31\u53ef\u4ee5\u4f7f\u5f97\u66f4\u591a\u7684\u5143\u7d20\u76f4\u63a5\u8fde\u63a5\u5728\u6839\u4e0a\uff0c\u8fd9\u6837\u5c31\u5b8c\u6210\u4e86\u5bf9\u6811\u7684\u538b\u7f29\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"cpp\">int find(int x)\n   \/\/\u67e5\u627e\u6839\n{\n    if (x!=pre&#91;x]) pre&#91;x]=find(pre&#91;x]);\n    return pre&#91;x];\n}<\/code><\/pre>\n\n\n\n<p>\u6240\u4ee5\u5982\u679c\u60f3\u8981\u5224\u65ad\u4e24\u4e2a\u5143\u7d20\u662f\u5426\u5c5e\u4e8e\u540c\u4e00\u96c6\u5408\u65f6\uff0c\u53ea\u9700\u8981\u5206\u522b\u67e5\u627e\u8fd9\u4e24\u4e2a\u5143\u7d20\u6240\u5728\u6811\u7684\u6839\uff0c\u5224\u65ad\u6839\u662f\u5426\u4e00\u81f4\u5373\u53ef\u3002\u5982\u679c\u5904\u4e8e\u4e0d\u540c\u96c6\u5408\uff0c\u5219\u6839\u4e0d\u540c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"cpp\">int x0=find(x);\nint y0=find(y);\nif (x0==y0) cout&lt;&lt;\"Y\"&lt;&lt;endl;\nelse cout&lt;&lt;\"N\"&lt;&lt;endl;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Part 2. \u8bad\u7ec3\u9898\u9898\u89e3<\/h2>\n\n\n\n<p>\u5bd2\u5047\u7b97\u6cd5\u8bad\u7ec3\uff08\u4e00\uff09\u6570\u636e\u7ed3\u6784\u57fa\u7840<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">#Algo0101. Look Up S<\/h3>\n\n\n\n<p><a href=\"https:\/\/hydro.ac\/d\/ahuacm\/p\/Algo0101\" data-type=\"URL\" data-id=\"https:\/\/hydro.ac\/d\/ahuacm\/p\/Algo0101\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >\u9898\u76ee\u63cf\u8ff0<\/a><\/p>\n\n\n\n<p>\u672c\u9898\u4e3a\u5355\u8c03\u6808\u6a21\u7248\u9898\u3002\u6bcf\u5934\u5976\u725b\u5411\u53f3\u770b\uff0c\u6c42\u51fa\u6bcf\u53ea\u5976\u725b\u79bb\u5979\u6700\u8fd1\u7684\u4ef0\u671b\u5bf9\u8c61\uff0c\u4e5f\u5c31\u662f\u6c42\u51fa\u53f3\u8fb9\u7b2c\u4e00\u4e2a\u5927\u4e8e\u81ea\u5df1\u7684\u6570\u3002\u4ece\u53f3\u5f80\u5de6\u7ef4\u62a4\u4e00\u4e2a\u4e25\u683c\u5355\u589e\u7684\u5355\u8c03\u6808\u5373\u53ef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int n,a&#91;1000006],b&#91;1000006];\nstack&lt;pair&lt;int,int&gt;&gt; q;\nint main()\n{\n    \/\/ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n    CI n;\n    CII(a,1,n);\n    FD(i,n,1)\n    {\n        while (!q.empty()&amp;&amp;a&#91;i]&gt;=q.top().first)\n            q.pop();\n        if (q.empty()) b&#91;i]=0;\n        else b&#91;i]=q.top().second;\n        q.push(make_pair(a&#91;i],i));\n    }\n    F(i,1,n)\n        CO b&#91;i] L;\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">#Algo0102. Bad Hair Day S<\/h3>\n\n\n\n<p><a href=\"https:\/\/hydro.ac\/d\/ahuacm\/p\/Algo0102?lang=en\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >\u9898\u76ee\u63cf\u8ff0<\/a><\/p>\n\n\n\n<p>\u672c\u9898\u6c42\u80fd\u770b\u89c1\u591a\u5c11\u4e2a\u725b\u7684\u5934\u53d1\uff0c\u5373\u5f53\u725b\u5411\u53f3\u770b\u65f6\uff0c\u6709\u591a\u5c11\u5934\u725b\u7684\u8eab\u9ad8\u662f\u5c0f\u4e8e\u81ea\u5df1\u7684\uff0c\u76f4\u5230\u9047\u5230\u5347\u9ad8\u5927\u4e8e\u81ea\u5df1\u7684\u725b\u3002\u53ef\u4ee5\u8f6c\u6362\u4ee5\u4e0b\u601d\u8def\uff0c\u5c06\u770b\u89c1\u591a\u5c11\u5934\u725b\u8f6c\u6362\u4e3a\u88ab\u591a\u5c11\u5934\u725b\u770b\u89c1\u81ea\u5df1\u7684\u5934\u53d1\u3002\u80fd\u770b\u89c1\u81ea\u5df1\u5934\u53d1\u7684\u725b\uff0c\u5fc5\u7136\u662f\u5904\u4e8e\u5de6\u8fb9\u4e14\u9ad8\u4e8e\u81ea\u5df1\u7684\u725b\uff0c\u800c\u4e14\u4e2d\u95f4\u6ca1\u6709\u6bd4\u89c2\u5bdf\u8005\u66f4\u9ad8\u7684\u725b\u963b\u9694\u3002\u6240\u4ee5\u53ef\u4ee5\u4ece\u5de6\u5230\u53f3\u7ef4\u62a4\u4e00\u4e2a\u4e25\u683c\u5355\u51cf\u7684\u5355\u8c03\u6808\uff0c\u800c\u6bcf\u6b21\u7ef4\u62a4\u5b8c\u6808\u540e\uff0c\u6808\u4e2d\u7684\u5143\u7d20\u4e2a\u6570\u4fbf\u662f\u80fd\u770b\u5230\u81ea\u5df1\u7684\u725b\u7684\u4e2a\u6570\u3002\u4f46\u662f\u7531\u4e8eSTL\u5185\u7f6e\u7684\u6808\u5e76\u4e0d\u80fd\u67e5\u8be2\u6808\u5185\u5143\u7d20\u4e2a\u6570\uff0c\u6240\u4ee5\u53ef\u4ee5\u5728\u5165\u6808\u548c\u51fa\u6808\u65f6\u8fdb\u884c\u8ba1\u6570\uff0c\u4e5f\u53ef\u4ee5\u81ea\u5df1\u5199\u4e00\u5957\u6808\u7684\u51fd\u6570\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>LL n,a&#91;80004],ans;\nstruct myStack\n{\n    int a&#91;80004],index=0;\n    int empty()\n    {\n        return index==0;\n    }\n    int top()\n    {\n        return a&#91;index];\n    }\n    void push(int x)\n    {\n        a&#91;++index]=x;\n    }\n    void pop()\n    {\n        index--;\n    }\n    int ind()\n    {\n        return index;\n    }\n} q;\nint main()\n{\n    \/\/ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n    CI n;\n    CII(a,1,n);\n    F(i,1,n)\n    {\n        while (!q.empty()&amp;&amp;a&#91;i]&gt;=q.top())\n            q.pop();\n        if (!q.empty()) ans+=q.ind();\n        q.push(a&#91;i]);\n    }\n    CO ans L;\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">#Algo0103. \u7389\u87fe\u5bab<\/h3>\n\n\n\n<p><a href=\"https:\/\/hydro.ac\/d\/ahuacm\/p\/Algo0103\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >\u9898\u76ee\u63cf\u8ff0<\/a><\/p>\n\n\n\n<p>\u672c\u9898\u9700\u8981\u6c42\u7531F\u6784\u6210\u7684\u6700\u5927\u7684\u77e9\u5f62\u9762\u79ef\u3002\u5728\u6c42\u6700\u5927\u77e9\u5f62\u9762\u79ef\u65f6\uff0c\u53ef\u4ee5\u5229\u7528\u5355\u8c03\u6808\u6765\u5feb\u901f\u627e\u5230\u6700\u5927\u7684\u9762\u79ef\u3002\u5148\u9009\u4e2d\u4e00\u884c\uff0c\u5c06\u6bcf\u4e00\u5217\u89c6\u4e3a\u4e00\u4e2a\u77e9\u5f62\uff0c\u5e76\u6c42\u51fa\u8be5\u884c\u4e2d\u6bcf\u4e00\u5217\u7684F\u5411\u4e0a\u6700\u5927\u80fd\u5ef6\u4f38\u7684\u9ad8\u5ea6\u4e3a\u591a\u5c11\uff0c\u5c06\u5176\u5b9a\u4e3a\u6bcf\u4e00\u5217\u7684\u9ad8\u5ea6\u3002\u8fd9\u6837\u5c31\u5c06\u4e8c\u7ef4\u4e2d\u5bfb\u627e\u6700\u5927\u77e9\u5f62\u9762\u79ef\u8f6c\u6362\u4e3a\u4e86\u7ed9\u5b9a\u6bcf\u4e2a\u77e9\u5f62\u7684\u9ad8\u5ea6\uff0c\u5728\u5176\u4e2d\u5bfb\u627e\u6700\u5927\u77e9\u5f62\u9762\u79ef\u3002\u7136\u540e\u5bf9\u6bcf\u4e00\u884c\u5e94\u7528\u4e00\u6b21\u8fd9\u6837\u7684\u8ba1\u7b97\uff0c\u4fbf\u80fd\u5f97\u5230\u6700\u7ec8\u6700\u5927\u7684\u77e9\u5f62\u9762\u79ef\u3002\u5bf9\u4e8e\u7ed9\u5b9a\u6bcf\u4e2a\u77e9\u5f62\u9ad8\u5ea6\u6c42\u5176\u4e2d\u7684\u6700\u5927\u9762\u79ef\uff0c\u9996\u5148\u9700\u8981\u9009\u4e2d\u4e00\u4e2a\u77e9\u5f62\u9ad8\u5ea6\uff0c\u5e76\u7531\u8be5\u9ad8\u5ea6\u6784\u6210\u5927\u77e9\u5f62\uff0c\u8fd9\u65f6\u8fd8\u9700\u8981\u6c42\u51fa\u8be5\u9ad8\u5ea6\u80fd\u591f\u5f97\u5230\u7684\u6700\u5927\u5bbd\u5ea6\u4e3a\u591a\u5c11\u3002\u6700\u5927\u5bbd\u5ea6\u662f\u6839\u636e\u88ab\u9009\u5b9a\u77e9\u5f62\u7684\u5de6\u53f3\u4e24\u8fb9\u6709\u591a\u5c11\u4e2a\u9ad8\u5ea6\u5927\u4e8e\u5b83\u7684\u77e9\u5f62\uff0c\u4e5f\u5c31\u662f\u9700\u8981\u5206\u522b\u627e\u5230\u5de6\u53f3\u7b2c\u4e00\u4e2a\u5c0f\u4e8e\u5b83\u7684\u9ad8\u5ea6\u7684\u77e9\u5f62\u3002\u8fd9\u5c31\u5c06\u95ee\u9898\u53c8\u8f6c\u53d8\u4e3a\u4e86\u5355\u8c03\u6808\u95ee\u9898\u3002\u53ef\u4ee5\u5229\u7528\u5355\u8c03\u6808\u5206\u522b\u627e\u5230\u5de6\u53f3\u7b2c\u4e00\u4e2a\u9ad8\u5ea6\u5c0f\u4e8e\u88ab\u9009\u5b9a\u77e9\u5f62\u7684\u4f4d\u7f6e\uff0c\u76f8\u51cf\u5c31\u80fd\u5f97\u5230\u5927\u77e9\u5f62\u7684\u5bbd\uff0c\u7136\u540e\u4e0e\u9ad8\u76f8\u4e58\u5f97\u5230\u9762\u79ef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int n,m,a&#91;1003]&#91;1003],b&#91;1003],l&#91;1003],r&#91;1003],ans;\nchar c;\n\nvoid findRMin(int n,int a&#91;],int b&#91;])   \/\/\u5355\u8c03\u6808\u5bfb\u627e\u53f3\u8fb9\u7b2c\u4e00\u4e2a\u6bd4\u81ea\u5df1\u5c0f\u7684\u5143\u7d20\u7684\u5750\u6807\n{\n    stack&lt;pair&lt;int,int&gt;&gt; q;\n    FD(i,n,1)\n    {\n        while (!q.empty()&amp;&amp;a&#91;i]&lt;=q.top().first)\n            q.pop();\n        if (q.empty()) b&#91;i]=n+1;\n        else b&#91;i]=q.top().second;\n        q.push(make_pair(a&#91;i],i));\n    }\n}\n\nvoid findLMin(int n,int a&#91;],int b&#91;])   \/\/\u5355\u8c03\u6808\u5bfb\u627e\u5de6\u8fb9\u7b2c\u4e00\u4e2a\u6bd4\u81ea\u5df1\u5c0f\u7684\u5143\u7d20\u7684\u5750\u6807\n{\n    stack&lt;pair&lt;int,int&gt;&gt; q;\n    F(i,1,n)\n    {\n        while (!q.empty()&amp;&amp;a&#91;i]&lt;=q.top().first)\n            q.pop();\n        if (q.empty()) b&#91;i]=0;\n        else b&#91;i]=q.top().second;\n        q.push(make_pair(a&#91;i],i));\n    }\n}\n\nint main()\n{\n    \/\/ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n    CI n&gt;&gt;m;\n    F(i,1,n)\n        F(j,1,m)\n        {\n            CI c;\n            a&#91;i]&#91;j]=c=='R'?0:1;\n        }\n    \n    \n    F(i,1,n)\n   \/\/\u5bf9\u6bcf\u4e00\u884c\u90fd\u8fdb\u884c\u4e00\u6b21\u8fd0\u7b97\n    {\n        F(j,1,m)\n  \/\/\u5148\u6c42\u51fa\u6bcf\u5217\u5411\u4e0a\u6700\u5927\u7684\u5ef6\u4f38\u9ad8\u5ea6\n        {\n            b&#91;j]=0;\n            FD(k,i,1)\n                if (a&#91;k]&#91;j]) b&#91;j]++;\n                else break;\n        }\n        findLMin(m,b,l);\n   \/\/\u6c42\u51fa\u6bcf\u4e00\u5217\u5de6\u4fa7\u7b2c\u4e00\u4e2a\u5c0f\u4e8e\u81ea\u5df1\u9ad8\u5ea6\u7684\u5217\n        findRMin(m,b,r);\n   \/\/\u6c42\u51fa\u6bcf\u4e00\u5217\u53f3\u4fa7\u7b2c\u4e00\u4e2a\u5c0f\u4e8e\u81ea\u5df1\u9ad8\u5ea6\u7684\u5217\n        F(j,1,m)\n   \/\/\u5bf9\u6bcf\u4e00\u5217\u5206\u522b\u8ba1\u7b97\u77e9\u5f62\u9762\u79ef\n        {\n            ans=max(ans,b&#91;j]*(r&#91;j]-l&#91;j]-1));\n        }\n    }\n\n    CO ans*3 L;\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">#Algo0104. \u6ed1\u52a8\u7a97\u53e3<\/h3>\n\n\n\n<p><a href=\"https:\/\/hydro.ac\/d\/ahuacm\/p\/Algo0104\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >\u9898\u76ee\u63cf\u8ff0<\/a><\/p>\n\n\n\n<p>\u8be5\u9898\u4e3a\u5355\u8c03\u961f\u5217\u7684\u6a21\u7248\u9898\u3002\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u9700\u8981\u5206\u522b\u6c42\u89e3\u3002\u9996\u5148\u9700\u8981\u4e24\u4e2a\u6307\u9488\u5206\u522b\u6307\u5411\u961f\u5217\u7684\u5f00\u5934\u548c\u7ed3\u5c3e\u3002\u4ece\u5de6\u5230\u53f3\u4f9d\u6b21\u904d\u5386\u6bcf\u4e00\u4e2a\u5143\u7d20\uff0c\u5728\u6c42\u7a97\u53e3\u6700\u5c0f\u503c\u65f6\uff0c\u9700\u8981\u4ece\u961f\u5217\u672b\u5c3e\u4e2d\u5c06\u5927\u4e8e\u5f53\u524d\u5143\u7d20\u7684\u5143\u7d20\u90fd\u79fb\u9664\u961f\u5217\uff0c\u56e0\u4e3a\u6bcf\u6b21\u904d\u5386\u65f6\uff0c\u90fd\u610f\u5473\u7740\u5f53\u524d\u5143\u7d20\u88ab\u52a0\u5165\u5230\u7a97\u53e3\u4e2d\uff0c\u540c\u65f6\u4e5f\u610f\u5473\u7740\u961f\u5217\u4e2d\u90a3\u4e9b\u5927\u4e8e\u5f53\u524d\u5143\u7d20\u7684\u5143\u7d20\u90fd\u518d\u4e5f\u4e0d\u53ef\u80fd\u6210\u4e3a\u6700\u5c0f\u503c\uff0c\u6240\u4ee5\u5c06\u5176\u79fb\u51fa\u961f\u5217\u3002\u540c\u65f6\u6bcf\u6b21\u90fd\u8981\u5224\u65ad\u4e00\u6b21\u961f\u5217\u5934\u90e8\u662f\u5426\u5df2\u7ecf\u8d85\u51fa\u4e86\u7a97\u53e3\u4e86\uff0c\u5e76\u79fb\u9664\u8d85\u51fa\u7684\u5143\u7d20\u3002\u540c\u65f6\u7531\u4e8e\u961f\u5217\u91cc\u7684\u5143\u7d20\u4e25\u683c\u5355\u8c03\u9012\u589e\uff0c\u6240\u4ee5\u961f\u5217\u5934\u90e8\u5373\u4e3a\u5f53\u524d\u7a97\u53e3\u7684\u6700\u5c0f\u503c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"cpp\">int n,k,f,h;\nLL a&#91;1000006],p&#91;1000006];\nint main()\n{\n    \/\/ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n    CI n&gt;&gt;k;\n    CII(a,1,n)\n\n    f=1,h=0;\n    F(i,1,n)\n    {\n        while (f&lt;=h&amp;&amp;a&#91;p&#91;h]]&gt;=a&#91;i])\n            h--;\n        p&#91;++h]=i;\n        if (p&#91;f]&lt;i-k+1) f++;\n        if (i&gt;=k) CO a&#91;p&#91;f]] P;\n    }\n    CL\n\n    f=1,h=0;\n    F(i,1,n)\n    {\n        while (f&lt;=h&amp;&amp;a&#91;p&#91;h]]&lt;=a&#91;i])\n            h--;\n        p&#91;++h]=i;\n        if (p&#91;f]&lt;i-k+1) f++;\n        if (i&gt;=k) CO a&#91;p&#91;f]] P;\n    }\n    CL\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">#Algo0105. \u5408\u5e76\u679c\u5b50<\/h3>\n\n\n\n<p><a href=\"https:\/\/hydro.ac\/d\/ahuacm\/p\/Algo0105\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >\u9898\u76ee\u63cf\u8ff0<\/a><\/p>\n\n\n\n<p>\u4e3a\u4e86\u4ee5\u6700\u5c11\u4f53\u529b\u5408\u5e76\u679c\u5b50\uff0c\u9700\u8981\u6bcf\u6b21\u90fd\u627e\u51fa\u91cd\u91cf\u6700\u5c0f\u7684\u4e24\u5806\u679c\u5b50\u8fdb\u884c\u5408\u5e76\uff0c\u7136\u540e\u518d\u5c06\u5408\u5e76\u540e\u7684\u91cd\u91cf\u52a0\u56de\u679c\u5b50\u961f\u5217\uff0c\u7136\u540e\u8fdb\u884c\u4e0b\u4e00\u6b21\u627e\u51fa\u91cd\u91cf\u6700\u5c0f\u7684\u4e24\u5806\u679c\u5b50\u3002\u5bf9\u4e8e\u8fd9\u79cd\u9700\u8981\u591a\u6b21\u5bfb\u627e\u6700\u5c0f\u503c\u7684\u64cd\u4f5c\uff0c\u53ef\u4ee5\u7528\u4f18\u5148\u961f\u5217\u7684\u5c0f\u6839\u5806\u6765\u505a\u3002\u4f18\u5148\u961f\u5217\u4f1a\u5728\u6bcf\u6b21\u52a0\u5165\u65b0\u5143\u7d20\u65f6\u81ea\u52a8\u8fdb\u884c\u6392\u5e8f\u4e14\u65f6\u95f4\u6548\u7387\u9ad8\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"cpp\">priority_queue&lt;LL,vector&lt;LL>,greater&lt;LL>> q;\nLL n,a,ans;\nint main()\n{\n    \/\/ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n    CI n;\n    F(i,1,n)\n    {\n        CI a;\n        q.push(a); \n    }\n    F(i,1,n-1)\n    {\n        LL a=q.top();\n        q.pop();\n        LL b=q.top();\n        q.pop();\n        ans+=a+b;\n        q.push(a+b);\n    }\n    CO ans L;\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">#Algo0106. \u4e8e\u662f\u4ed6\u9519\u8bef\u7684\u70b9\u540d\u5f00\u59cb\u4e86<\/h3>\n\n\n\n<p><a href=\"https:\/\/hydro.ac\/d\/ahuacm\/p\/Algo0106\" data-type=\"URL\" data-id=\"https:\/\/hydro.ac\/d\/ahuacm\/p\/Algo0106\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >\u9898\u76ee\u63cf\u8ff0<\/a><\/p>\n\n\n\n<p>\u672c\u9898\u9700\u8981\u67e5\u627e\u6240\u7ed9\u5b57\u7b26\u4e32\u662f\u5426\u5b58\u5728\uff0c\u540c\u65f6\u7edf\u8ba1\u4e00\u4e2a\u5b57\u7b26\u4e32\u88ab\u67e5\u627e\u7684\u6b21\u6570\u3002\u5bf9\u4e8e\u8fd9\u79cd\u5927\u6279\u91cf\u67e5\u627e\u5b57\u7b26\u4e32\u7684\u64cd\u4f5c\uff0c\u5982\u679c\u4f7f\u7528\u7b80\u5355\u7684\u5bf9\u6bd4\uff0c\u5219\u4f1a\u5b58\u5728\u5927\u91cf\u4e0d\u5fc5\u8981\u7684\u5bf9\u6bd4\u3002\u6240\u4ee5\u9700\u8981\u4f7f\u7528\u5b57\u5178\u6811\u6765\u5feb\u901f\u67e5\u627e\u5b57\u7b26\u4e32\u3002\u7531\u4e8e\u9898\u76ee\u9700\u8981\u7edf\u8ba1\u4e00\u4e2a\u5b57\u7b26\u4e32\u88ab\u67e5\u627e\u7684\u6b21\u6570\u6765\u5224\u8bfb\u662f\u5426\u5b58\u5728\u91cd\u590d\u70b9\u540d\uff0c\u6240\u4ee5\u5bf9\u5b57\u5178\u6811\u7684\u8282\u70b9\u8fdb\u884c\u6539\u9020\uff0c\u4f7f\u5176\u5728\u8bb0\u5f55\u662f\u5426\u4e3a\u5355\u8bcd\u7ed3\u5c3e\u7684\u540c\u65f6\uff0c\u8bb0\u5f55\u8be5\u5355\u8bcd\u7ed3\u5c3e\u662f\u5426\u88ab\u67e5\u627e\u8fc7\u3002\u5f53\u8be5\u5355\u8bcd\u7ed3\u5c3e\u88ab\u67e5\u627e\u65f6\uff0c\u8fdb\u884c\u6807\u8bb0\u6216\u8fd4\u56de\u88ab\u91cd\u590d\u67e5\u627e\u7684\u4fe1\u606f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"cpp\">int n;\nstring s;\n\nstruct trie\n{\n    int next&#91;26]; \n    int isEnd;\n    int call; \n   \/\/\u8bb0\u5f55\u8be5\u5355\u8bcd\u7ed3\u5c3e\u662f\u5426\u88ab\u67e5\u627e\u8fc7\n}tree&#91;500005];\nint inc;\n\nint insert(string s)  \n{\n    int p=0;   \n    for (int i=0;i&lt;s.size();i++)   \n    {\n        if (tree&#91;p].next&#91;s&#91;i]-97]) p=tree&#91;p].next&#91;s&#91;i]-97];\n        else  \n        {\n            inc++;  \n            tree&#91;p].next&#91;s&#91;i]-97]=inc;  \n            p=inc;   \n        }\n    }\n    if (tree&#91;p].isEnd) return 1;   \n    else tree&#91;p].isEnd=1;  \n    return 0;\n}\n\nint check(string s)   \n{\n    int p=0;   \n    for (int i=0;i&lt;s.size();i++)   \n    {\n        if (!tree&#91;p].next&#91;s&#91;i]-97]) return 0;   \n        p=tree&#91;p].next&#91;s&#91;i]-97];  \n    }\n    if (tree&#91;p].call) return -1;\n   \/\/\u9996\u5148\u9700\u8981\u5224\u65ad\u8be5\u5355\u8bcd\u662f\u5426\u88ab\u67e5\u627e\u8fc7\uff0c\u5982\u679c\u88ab\u67e5\u627e\u8fc7\uff0c\u5219\u8bf4\u660e\u8be5\u5355\u8bcd\u5b58\u5728\u3002\n    if (!tree&#91;p].isEnd) return 0;\n   \/\/\u5728\u6ca1\u88ab\u67e5\u627e\u8fc7\u7684\u57fa\u7840\u4e0a\uff0c\u518d\u5224\u65ad\u8be5\u5355\u8bcd\u662f\u5426\u5b58\u5728\n    tree&#91;p].call=1;\n   \/\/\u6807\u8bb0\u8be5\u5355\u8bcd\u88ab\u67e5\u627e\u8fc7\uff0c\u5e76\u8fd4\u56de\u5355\u8bcd\u5b58\u5728\n    return 1;\n}\n\nint main()\n{\n    \/\/ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n    CI n;\n    F(i,1,n)\n    {\n        CI s;\n        insert(s);\n    }\n\n    CI n;\n    F(i,1,n)\n    {\n        CI s;\n        switch (check(s))\n        {\n            case 1: CO \"OK\" L; break;\n            case 0: CO \"WRONG\" L; break;\n            case -1: CO \"REPEAT\" L; break;\n        }\n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">#Algo0107. Minimum Array<\/h3>\n\n\n\n<p><a href=\"https:\/\/hydro.ac\/d\/ahuacm\/p\/Algo0107\" data-type=\"URL\" data-id=\"https:\/\/hydro.ac\/d\/ahuacm\/p\/Algo0107\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >\u9898\u76ee\u63cf\u8ff0<\/a><\/p>\n\n\n\n<p>\u5bf9\u7ed9\u5b9a\u7684b\u6570\u7ec4\u8fdb\u884c\u6392\u5e8f\uff0c\u4f7f\u5f97\u6570\u7ec4c\uff1a[latex](a_i+b_i)%n[\/latex]\u7684\u5b57\u5178\u5e8f\u6700\u5c0f\u3002\u4f7f\u5b57\u5178\u5e8f\u6700\u5c0f\uff0c\u5373\u5c3d\u91cf\u8ba90\u9760\u524d\uff0c\u4e5f\u5c31\u662f[latex]b_i=n-a_i[\/latex]\uff0c\u7136\u540e\u662f\u6570\u5b57\u5c0f\u7684\u9760\u524d\u3002\u6240\u4ee5\u53ef\u4ee5\u4f7f\u7528\u53ef\u91cd\u590d\u7684\u96c6\u5408multiset\u8fdb\u884c\u64cd\u4f5c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"cpp\">int n,a&#91;200005],ans,x;\nmultiset&lt;int> s;\nint main()\n{\n    \/\/ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n    CI n;\n    CII(a,1,n)\n    F(i,1,n)\n    {\n        CI x;\n        s.insert(x);\n    }\n\n    F(i,1,n)\n    {\n        auto it=s.lower_bound(n-a&#91;i]);\n   \/\/\u5bfb\u627en-a&#91;i]\u5e76\u5224\u65ad\u662f\u5426\u5b58\u5728\n        if (it==s.end()) it=s.begin();\n   \/\/\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5219\u9009\u62e9\u96c6\u5408\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\uff0c\u5373\u6700\u5c0f\u7684\u5143\u7d20\n        CO (*it+a&#91;i])%n P;\n        s.erase(it);\n    }\n    CL\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">#Algo0108. \u56e2\u4f19<\/h3>\n\n\n\n<p><a href=\"https:\/\/hydro.ac\/d\/ahuacm\/p\/Algo0108\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >\u9898\u76ee\u63cf\u8ff0<\/a><\/p>\n\n\n\n<p>\u672c\u9898\u7684\u4e3b\u8981\u64cd\u4f5c\u4e3a\u5408\u5e76\u96c6\u5408\u4ee5\u53ca\u5224\u65ad\u4e24\u4e2a\u5143\u7d20\u662f\u5426\u5728\u540c\u4e00\u96c6\u5408\u4e2d\uff0c\u4f7f\u7528\u5e76\u67e5\u96c6\u5373\u53ef\u3002\u672c\u9898\u4e2d\u201c\u670b\u53cb\u7684\u670b\u53cb\u662f\u670b\u53cb\u201d\uff0c\u5c06\u4e24\u4e2a\u4e3a\u670b\u53cb\u7684\u5143\u7d20\u6240\u5728\u96c6\u5408\u8fdb\u884c\u5408\u5e76\u5373\u53ef\u3002\u4f46\u662f\u5bf9\u4e8e\u201c\u654c\u4eba\u7684\u654c\u4eba\u662f\u654c\u4eba\u201d\uff0c\u65e0\u6cd5\u8fdb\u884c\u76f4\u63a5\u7684\u5408\u5e76\u3002\u5047\u8bbe\u4e00\u4e2a\u4eba\u7684\u7f16\u53f7\u4e3aa\uff0c\u603b\u5171n\u4e2a\u4eba\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528a+n\u6765\u8868\u793a\u8ddf\u8fd9\u4e2a\u4eba\u662f\u654c\u4eba\u5173\u7cfb\u3002\u4e0e\u8fd9\u4e2a\u4eba\u662f\u654c\u4eba\u65f6\uff0c\u5c06\u7b2ca+n\u4e2a\u5143\u7d20\u6240\u5728\u96c6\u5408\u5408\u5e76\u5230\u81ea\u5df1\u7684\u96c6\u5408\u5c31\u53ef\u4ee5\u8868\u793a\u654c\u4eba\u5173\u7cfb\u4e86\uff0c\u8fd9\u65f6\u4e0ea\u4e3a\u654c\u4eba\u5173\u7cfb\u7684\u4eba\u81ea\u7136\u90fd\u5904\u5728\u4e86\u540c\u4e00\u4e2a\u96c6\u5408\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"cpp\">int n,m,x,y,ans;\nchar c;\nint pre&#91;200005];\n\nint find(int x)\n{\n    if (x!=pre&#91;x]) pre&#91;x]=find(pre&#91;x]);\n    return pre&#91;x];\n}\n\nvoid merge(int a,int b)\n{\n    int x=find(a);\n    int y=find(b);\n    pre&#91;x]=y;\n}\n\nint main()\n{\n    \/\/ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n    CI n>>m;\n    F(i,1,2*n)\n        pre&#91;i]=i;\n\n    F(i,1,m)\n    {\n        CI c>>x>>y;\n        if (c=='E') \n        {\n            merge(x,y+n);\n            merge(x+n,y);\n        }\n        else merge(x,y);\n    }\n    F(i,1,n)\n        find(i);\n    sort(pre+1,pre+n+1);\n    F(i,1,n)\n        if (pre&#91;i]!=pre&#91;i-1]) ans++;\n    \n    CO ans L;\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Part 3.Codeforces\u9898\u89e3<\/h2>\n\n\n\n<p>\u9898\u76ee\u94fe\u63a5\uff1a<a href=\"https:\/\/codeforces.com\/contest\/1907\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >https:\/\/codeforces.com\/contest\/1907<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">A. Rook<\/h3>\n\n\n\n<p>\u96be\u5ea6\uff1a800<\/p>\n\n\n\n<p>\u6839\u636e\u8f93\u5165\uff0c\u5faa\u73af\u8f93\u51fa\u884c\u548c\u5217\u5e76\u8df3\u8fc7\u68cb\u5b50\u6240\u5728\u4f4d\u7f6e\u5373\u53ef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int t,a;\nchar c;\nint main()\n{\n    \/\/ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n    CI t;\n    while (t--)\n    {\n        scanf(\"\\n%c%d\",&amp;c,&amp;a);\n        F(i,1,8)\n            if (i!=a) CO c&lt;&lt;i L;\n        F(i,97,104)\n            if (i!=c) CO (char)i&lt;&lt;a L;\n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">B. YetnotherrokenKeoard<\/h3>\n\n\n\n<p>\u96be\u5ea6\uff1a1000<\/p>\n\n\n\n<p>\u9047\u5230\u5b57\u7b26b\u65f6\uff0c\u5220\u9664\u5176\u524d\u9762\u79bb\u4ed6\u6700\u8fd1\u7684\u4e00\u4e2a\u5c0f\u5199\u5b57\u6bcd\uff0c\u5982\u679c\u6ca1\u6709\u5c31\u4e0d\u5220\u9664\u3002\u9047\u5230\u5b57\u6bcdB\u65f6\uff0c\u5220\u9664\u5176\u524d\u9762\u79bb\u4ed6\u6700\u8fd1\u7684\u4e00\u4e2a\u5927\u5199\u5b57\u6bcd\uff0c\u5982\u679c\u6ca1\u6709\u5c31\u4e0d\u5220\u9664\u3002<\/p>\n\n\n\n<p>\u4e3a\u4e86\u5feb\u901f\u5b8c\u6210\u6dfb\u52a0\u5b57\u7b26\u548c\u5220\u9664\u5b57\u7b26\u7684\u64cd\u4f5c\uff0c\u53ef\u4ee5\u7ef4\u62a4\u4e24\u4e2a\u6808\uff0c\u5206\u522b\u8868\u793a\u5927\u5199\u5b57\u6bcd\u548c\u5c0f\u5199\u5b57\u6bcd\uff0c\u6808\u4e2d\u5b58\u50a8\u7740\u5b57\u7b26\u7684\u4f4d\u7f6e\u3002\u9700\u8981\u5220\u9664\u5927\u5c0f\u5b57\u6bcd\u65f6\uff0c\u5c31\u5f39\u51fa\u5bf9\u5e94\u7684\u6808\u9876\u5143\u7d20\uff0c\u6700\u540e\u5c06\u4e24\u4e2a\u6808\u5b58\u50a8\u5230\u540c\u4e00\u4e2a\u6570\u7ec4\u7136\u540e\u4ece\u5c0f\u5230\u5927\u6392\u5e8f\uff0c\u5c31\u53ef\u4ee5\u5f97\u5230\u6700\u540e\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int t,ans&#91;1000006];\nstring s;\nstack&lt;int&gt; A,a;\nint main()\n{\n    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n    CI t;\n    while (t--)\n    {\n        CI s;\n        F(i,0,s.size()-1)\n        {\n            if (s&#91;i]=='b')\n            {\n                if (!a.empty()) a.pop();\n            } \n            elif (s&#91;i]=='B')\n            {\n                if (!A.empty()) A.pop();\n            }\n            else\n            {\n                if (s&#91;i]&gt;='A'&amp;&amp;s&#91;i]&lt;='Z') A.push(i);\n                else a.push(i);\n            }\n        }\n        \n        clear(ans);\n        int t=0;\n        while (!a.empty())\n        {\n            ans&#91;t++]=a.top();\n            a.pop();\n        }\n        while (!A.empty())\n        {\n            ans&#91;t++]=A.top();\n            A.pop();\n        }\n        sort(ans,ans+t);\n        F(i,0,t-1)\n            CO s&#91;ans&#91;i]];\n        CL\n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">C. Removal of Unattractive Pairs<\/h3>\n\n\n\n<p>\u96be\u5ea6\uff1a1200<\/p>\n\n\n\n<p>\u7528\u6876\u6765\u7edf\u8ba1\u6bcf\u4e2a\u5b57\u6bcd\u51fa\u73b0\u7684\u6b21\u6570\uff0c\u5982\u679c\u6ca1\u6709\u5b57\u6bcd\u8d85\u8fc7\u603b\u6570\u7684\u4e00\u534a\uff0c\u5219\u603b\u4f1a\u88ab\u6d88\u9664\u6389\uff0c\u5982\u679c\u8d85\u8fc7\u4e86\u4e00\u534a\uff0c\u5219\u80af\u5b9a\u6709\u4e00\u90e8\u5206\u8be5\u5b57\u6bcd\u65e0\u6cd5\u88ab\u6d88\u9664\u6389<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"cpp\">int t,n,a&#91;26];\nstring s;\nint main()\n{\n    \/\/ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n    CI t;\n    while (t--)\n    {\n        clear(a);\n        CI n;\n        CI s;\n        F(i,0,n-1)\n            a&#91;s&#91;i]-97]++;\n        \n        int m=0;\n        F(i,0,25)\n            m=max(m,a&#91;i]);\n        CO max(n%2,2*m-n) L;\n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">D. Jumping Through Segments<\/h3>\n\n\n\n<p>\u96be\u5ea6\uff1a1400<\/p>\n\n\n\n<p>\u672c\u9898\u9700\u8981\u7528\u4e8c\u5206\u67e5\u627e\uff0c\u6765\u627e\u5230\u4e00\u4e2a\u6700\u5c0f\u7684k\u3002\u5bf9\u4e8e\u4e8c\u5206\u67e5\u627e\u4e2d\u7684\u68c0\u67e5\u51fd\u6570\uff0c\u53ef\u4ee5\u6c42\u51fa\u4eba\u5728\u5f53\u524dk\u503c\u4e0b\u7684\u79fb\u52a8\u8303\u56f4\u4e0e\u76ee\u6807\u8303\u56f4\u7684\u4ea4\u96c6\uff0c\u4e0b\u4e00\u6b21\u4ee5\u8be5\u4ea4\u96c6\u4e3a\u57fa\u7840\uff0c\u6c42\u51fa\u4eba\u7684\u6700\u5927\u79fb\u52a8\u8303\u56f4\u4e0e\u76ee\u6807\u8303\u56f4\u7684\u4ea4\u96c6\u5e76\u4e0d\u65ad\u8fdb\u884c\u8be5\u6b65\u9aa4\uff0c\u5982\u679c\u5176\u4e2d\u4efb\u610f\u4e00\u6b21\u6c42\u4ea4\u96c6\u65f6\u53d1\u73b0\u5e76\u4e0d\u5b58\u5728\u4ea4\u96c6\uff0c\u5373\u4eba\u65e0\u6cd5\u79fb\u52a8\u5230\u76ee\u6807\u4f4d\u7f6e\uff0c\u5219\u5f53\u524dk\u503c\u65e0\u6cd5\u5f97\u5230\u7b54\u6848\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"cpp\">LL t,n,a&#91;200005],b&#91;200005];\n\nint check(LL k)\n{\n    LL l=0,r=0;\n    F(i,1,n)\n    {\n        l=max(l-k,a&#91;i]);\n        r=min(r+k,b&#91;i]);\n        if (l&gt;r) return 0;\n    }\n    return 1;\n}\n\nint main()\n{\n    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n    CI t;\n    while (t--)\n    {\n        CI n;\n        F(i,1,n)\n            CI a&#91;i]&gt;&gt;b&#91;i];\n        LL l=0,r=1e9;\n        while (l&lt;=r)\n        {\n            LL mid=(l+r)\/2;\n            if (check(mid)) r=mid-1;\n            else l=mid+1;\n        }\n        CO l L;\n    }\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Part 1.\u7b14\u8bb0 \u5355\u8c03\u6808 \u6a21\u7248 \u89e3\u91ca \u4ee5\u5bfb\u627e\u53f3\u8fb9\u7b2c\u4e00\u4e2a\u6bd4\u81ea\u5df1\u5c0f\u7684\u5143\u7d20\u7684\u5750\u6807\u4e3a\u4f8b\uff0c\u4ece\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u5f00\u59cb\u4ece\u53f3\u5f80\u5de6\u904d\u5386\uff0c\u6808q\u4e2d\u6309\u7167\u4ece\u9876\u5230 &#8230;<\/p>","protected":false},"author":1,"featured_media":1372,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28],"tags":[29],"class_list":["post-1367","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-28","tag-29"],"_links":{"self":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts\/1367","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/comments?post=1367"}],"version-history":[{"count":1,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts\/1367\/revisions"}],"predecessor-version":[{"id":1729,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts\/1367\/revisions\/1729"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/media\/1372"}],"wp:attachment":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/media?parent=1367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/categories?post=1367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/tags?post=1367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}