{"id":365,"date":"2020-04-22T19:55:44","date_gmt":"2020-04-22T11:55:44","guid":{"rendered":"http:\/\/bytew.net\/?p=365"},"modified":"2021-09-08T20:20:07","modified_gmt":"2021-09-08T12:20:07","slug":"noi2018%e5%86%92%e6%b3%a1%e6%8e%92%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/bytew.net\/?p=365","title":{"rendered":"[NOI2018]\u5192\u6ce1\u6392\u5e8f"},"content":{"rendered":"\n<p>\u4e00\u53e5\u8bdd\u9898\u610f\uff1a\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3an\u7684\u6392\u5217\uff0c\u6c42\u6709\u591a\u5c11\u957f\u5ea6\u4e3an\u7684\u6392\u5217\u4f7f\u5f97<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/bytew.net\/wp-content\/ql-cache\/quicklatex.com-b64340d5e6da61b9b69802282d4ee883_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#115;&#117;&#109;&#95;&#123;&#105;&#61;&#49;&#125;&#94;&#110;&#92;&#102;&#114;&#97;&#99;&#123;&#124;&#105;&#45;&#112;&#91;&#105;&#93;&#124;&#125;&#123;&#50;&#125;&#32;&#61;\" title=\"Rendered by QuickLaTeX.com\" height=\"32\" width=\"141\" style=\"vertical-align: -8px;\"\/>\u5192\u6ce1\u6392\u5e8f\u4ea4\u6362\u6570\u3002<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/bytew.net\/wp-content\/ql-cache\/quicklatex.com-966b4c1bfb6b0cf0694011fc3ee9a28f_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#110;&#32;&#92;&#108;&#101;&#32;&#54;&#48;&#48;&#48;&#48;&#48;&#44;&#32;&#92;&#115;&#117;&#109;&#32;&#110;&#32;&#92;&#108;&#101;&#32;&#50;&#48;&#48;&#48;&#48;&#48;&#48;\" title=\"Rendered by QuickLaTeX.com\" height=\"25\" width=\"279\" style=\"vertical-align: -7px;\"\/><\/p>\n\n\n\n<!--more-->\n\n\n\n<p>\u9996\u5148\uff0c\u53ef\u4ee5\u8bc1\u660e\u7ed9\u51fa\u7684\u6761\u4ef6\u5c31\u662f\u8981\u6c42\u6392\u5217\u4e2d\u6ca1\u6709\u4e00\u4e2a\u957f\u5ea6\u4e3a3\u7684\u4e0b\u964d\u5b50\u5e8f\u5217\u3002\u5982\u4f55\u8bc1\u660e\uff1f<\/p>\n\n\n\n<p>\u6253\u8868\u662f\u4e00\u79cd\u65b9\u6cd5\uff0c\u4f46\u662f\u6211\u8fd8\u60f3\u4e86\u4e00\u79cd\u8bc1\u660e\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<p>\u9996\u5148\uff0c\u6211\u4eec\u77e5\u9053\u7531\u4e8e\u6bcf\u4e00\u6b21\u5192\u6ce1\u6392\u5e8f\u4ea4\u6362\u90fd\u4f1a\u51cf\u5c11\u4e00\u4e2a\u9006\u5e8f\u5bf9\uff0c\u603b\u7684\u4ea4\u6362\u6570\u76ee\u5c31\u662f\u9006\u5e8f\u5bf9\u6570\u76ee\u3002\u90a3\u4e48\uff0c\u6211\u4eec\u5c31\u9700\u8981\u548c\u5f0f\u7684\u503c\u7b49\u4e8e\u9006\u5e8f\u5bf9\u4e2a\u6570\u3002\u6211\u4eec\u8fd8\u53ef\u4ee5\u628a<\/p>\n\n\n\n<p>\u8003\u8651\u6392\u5217\u4e2d\u7684\u7b2ci\u4f4d\u7684\u6570\u5b57p[i]\uff0c\u4e0d\u59a8\u8bbep[i]>i\u3002\u6211\u4eec\u628a\u6392\u5217\u4e2d\u5927\u4e8ep[i]\u7684\u6570\u5b57\u75281\u8868\u793a\uff0c\u5176\u4ed6\u6570\u5b57\u75280\u8868\u793a\uff0c\u90a3\u4e48\u6392\u5217\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n\n\n\n<p>0 0 0 0 0 i 0 0 1 1 0 0 1 0<\/p>\n\n\n\n<p>emmmmm\u5927\u6982\u5c31\u662f\u8bf4\u4e00\u5171\u4f1a\u6709n-p[i]\u4e2a1\uff0cp[i]-1\u4e2a0\u3002\u800c\u4e14\u5f88\u663e\u7136\uff0c\u5305\u542b\u8fd9\u4e2ai\u7684\u9006\u5e8f\u5bf9\uff0c\u4ec5\u4ec5\u662f\u4ee5i\u4e3a\u5de6\u7aef\u70b9\u7684\u5c31\u6709\u53f3\u9762\u76840\u90a3\u4e48\u591a\uff0c\u5c31\u662fp[i]-i\u90a3\u4e48\u591a\u3002\u5982\u679ci\u5de6\u8fb9\u67091\uff0c\u53f3\u9762\u7684\u96f6\u5c31\u4f1a\u66f4\u591a\uff0c\u5de6\u8fb9\u76841\u4e5f\u53ef\u4ee5\u548ci\u5f62\u6210\u9006\u5e8f\u5bf9\uff0c\u90a3\u4e48\u5c31\u4f1a\u8d85\u51fa\u9650\u5236\u3002\u8fd9\u6837\u6211\u4eec\u5c31\u77e5\u9053\u5bf9\u4e8e\u8fd9\u4e2ai\u6240\u6709\u5de6\u8fb9\u7684\u5143\u7d20\u90fd\u5c0f\u4e8e\u5b83\u3002\u518d\u540c\u7406\u8ba8\u8bbap[i]&lt;i\u548cp[i]=i\u7684\u60c5\u51b5\uff0c\u6211\u4eec\u53d1\u73b0\u7531\u4e8e\u6ca1\u6709\u5143\u7d20\u53ef\u4ee5\u5f53\u4e0b\u964d\u5b50\u5e8f\u5217\u7684\u4e2d\u95f4\u7684\u5143\u7d20\uff0c\u663e\u7136\u662f\u6ca1\u6709\u957f\u5ea6\u4e3a3\u7684\u4e0b\u964d\u5b50\u5e8f\u5217\u7684\u3002<\/p>\n\n\n\n<p>\u4e0b\u4e00\u6b65\u662f\u5c06\u4e00\u4e2a\u5408\u6cd5\u7684\u5b50\u5e8f\u5217\u8f6c\u5316\u6210\u4e00\u4e2a\u62ec\u53f7\u5e8f\u5217\u3002\u5982\u4f55\u8f6c\u5316\uff1f<\/p>\n\n\n\n<p>\u5199\u51fa\u4e00\u4e2adp\uff0c\u00a0<img decoding=\"async\" src=\"https:\/\/www.zhihu.com\/equation?tex=f_%7Bi%2Cj%7D\" alt=\"[\u516c\u5f0f]\">\u00a0\u8868\u793a\u653e\u4e86\u524d\u00a0<img decoding=\"async\" src=\"https:\/\/www.zhihu.com\/equation?tex=i\" alt=\"[\u516c\u5f0f]\">\u00a0\u4e2a\u6570\uff0c\u5269\u4f59\u7684\u6570\u4e2d\u6709\u00a0<img decoding=\"async\" src=\"https:\/\/www.zhihu.com\/equation?tex=j\" alt=\"[\u516c\u5f0f]\">\u00a0\u4e2a\u6570\u6bd4\u4e4b\u524d\u6700\u5927\u7684\u6570\u8981\u5927\u3002\u663e\u7136\u5c31\u6709\u4e24\u79cd\u8f6c\u79fb\uff0c\u4e00\u79cd\u662f\u653e\u4e00\u4e2a\u6bd4\u4e4b\u524d\u6700\u5927\u7684\u6570\u8981\u5927\u7684\u6570\uff0c\u8fd9\u4e2a\u662f\u6709\u00a0<img decoding=\"async\" src=\"https:\/\/www.zhihu.com\/equation?tex=j\" alt=\"[\u516c\u5f0f]\">\u00a0\u79cd\u653e\u6cd5\u3002\u4e00\u79cd\u662f\u653e\u4e00\u4e2a\u66f4\u5c0f\u7684\u6570\uff0c\u56e0\u4e3a\u8fd9\u4e2a\u66f4\u5c0f\u7684\u6570\u540e\u9762\u7684\u6570\u90fd\u5f97\u6bd4\u4ed6\u5927\u624d\u884c\uff0c\u6240\u4ee5\u5fc5\u987b\u662f\u6700\u5c0f\u7684\u6570\u3002\u6709\u4e00\u4e2acase\u662f\u4e0d\u80fd\u8d70\u7b2c\u4e8c\u79cd\u8f6c\u79fb\u7684\uff0c\u4e5f\u5c31\u662f\u00a0<img decoding=\"async\" src=\"https:\/\/www.zhihu.com\/equation?tex=j%3Dn-i\" alt=\"[\u516c\u5f0f]\">\u00a0\u7684case\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u6211\u4eec\u8003\u8651&nbsp;<img decoding=\"async\" src=\"https:\/\/www.zhihu.com\/equation?tex=j%27%3Dj-%28n-i%29\" alt=\"[\u516c\u5f0f]\">&nbsp;\u7684\u8bdd\uff0c\u76f8\u5f53\u4e8e\u662f\u4e8c\u7ef4\u5e73\u9762\u4e0a\u6bcf\u6b21\u7ed9&nbsp;<img decoding=\"async\" src=\"https:\/\/www.zhihu.com\/equation?tex=j%27\" alt=\"[\u516c\u5f0f]\">&nbsp;\u52a0\u4efb\u610f\u6570\uff0c\u6216\u8005\u662f\u7ed9&nbsp;<img decoding=\"async\" src=\"https:\/\/www.zhihu.com\/equation?tex=j%27\" alt=\"[\u516c\u5f0f]\">&nbsp;\u51cf1\uff0c\u5e76\u4e14\u4e0d\u80fd\u8d8a\u8fc7&nbsp;<img decoding=\"async\" src=\"https:\/\/www.zhihu.com\/equation?tex=j%27%3D0\" alt=\"[\u516c\u5f0f]\">&nbsp;\u7684\u4e00\u4e2a\u968f\u673a\u6e38\u8d70\uff0c\u6ca1\u6709\u9650\u5236\u7684\u65f6\u5019\u663e\u7136\u5bf9\u5e94\u4e86\u957f\u5ea6\u4e3a&nbsp;<img decoding=\"async\" src=\"https:\/\/www.zhihu.com\/equation?tex=2n\" alt=\"[\u516c\u5f0f]\">&nbsp;\u7684\u62ec\u53f7\u5e8f\u5217\uff0c\u5c31\u662f\u5361\u7279\u5170\u6570\u3002<\/p>\n\n\n\n<p>\uff08\u4e0a\u9762\u4e24\u6bb5\u6bb5\u6765\u81ea<a rel=\"noreferrer noopener\" href=\"https:\/\/www.zhihu.com\/question\/285383359\" target=\"_blank\">\u6b66\u5f18\u52cb\u7684\u77e5\u4e4e\u56de\u7b54<\/a>\uff09<\/p>\n\n\n\n<p>\u7528\u8bed\u8a00\u4e0d\u597d\u63cf\u8ff0\uff0c\u5199\u4e00\u70b9python\u4ee3\u7801\uff0c\u8bc1\u660e\u7559\u7ed9\u8bfb\u8005\uff08\u9e3d\uff09\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>seq = \"\"\nmx = 0\nfor i in range(1,n+1):\n    if p&#91;i]>mx:\n        seq+=\"(\"*(p&#91;i]-mx)\n        mx = p&#91;i]\n    seq+=\")\"<\/code><\/pre>\n\n\n\n<p>\u7136\u540e\u53ef\u4ee5\u8bc1\u660e\u8fd9\u662f\u4e00\u4e2a\u4e00\u4e00\u5bf9\u5e94\u7684\u5173\u7cfb\u3002<\/p>\n\n\n\n<p>\u5bf9\u4e8e\u4e00\u4e2a\u6709\u7740\u5b57\u5178\u5e8f\u9650\u5236\u7684\u60c5\u51b5\uff0c\u53ef\u4ee5\u904d\u5386\uff0c\u679a\u4e3e\u54ea\u91cc\u8d85\u8fc7\u4e86\u5b57\u5178\u5e8f\uff0c\u76f8\u5f53\u4e8e\u56fa\u5b9a\u4e86\u4e00\u4e2a\u5e8f\u5217\u7684\u524d\u7f00\u6c42\u65b9\u6848\u6570\u3002\u8fd9\u4e00\u6b65\u662f\u4e00\u4e2a\u7ecf\u5178\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e24\u4e2a\u7ec4\u5408\u6570\u76f8\u51cf\u6765\u6c42\u503c\u3002<\/p>\n\n\n\n<p>dbq\uff0c12\u70b930\u5206\u4e86\uff0c\u6211\u4e0d\u80fd\u5199\u4e86\uff0c\u6211\u597d\u722c\u554a\uff0c\u5e0c\u671b\u6211\u80fd\u505a\u66f4\u591a\u66f4\u597d\u7684\u9898\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;bits\/stdc++.h>\n\n\nusing namespace std;\ntypedef long long ll;\n#define set0(x) memset(x,0,sizeof(x))\n#define F first\n#define S second\n#define PB push_back\n#define MP make_pair\n#define rep(i, a, b) for(int i = a; i &lt; (b); ++i)\n#define trav(a, x) for(auto&amp; a : x)\n#define all(x) x.begin(), x.end()\n#define sz(x) (int)(x).size()\n\nll chkmax(ll &amp;a,ll b){return a = a>b?a:b;}\ntypedef long long ll;\ntypedef pair&lt;int,int> pii;\ntypedef pair&lt;ll,ll> pll;\ntypedef vector&lt;int> VI;\ntemplate&lt;typename T> void read(T &amp;x){\n\tx = 0;char ch = getchar();ll f = 1;\n\twhile(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}\n\twhile(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;\n}\ntemplate&lt;typename T, typename... Args> void read(T &amp;first, Args&amp; ... args) {\n\tread(first);\n\tread(args...);\n}\nint mod = 998244353;\ninline int mul(int x,int y){return 1ll*x*y%mod;}\ninline int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}\ninline int sub(int x,int y){return x-y&lt;0?x-y+mod:x-y;}\ninline int sq(int x){return 1ll*x*x%mod;}\nint mpow(int a,int b){return b == 0 ? 1 : ( b&amp;1 ? mul(a,sq(mpow(a,b\/2))) : sq(mpow(a,b\/2)));}\nconst int N = 1200000;\nint fac&#91;N+10],invfac&#91;N+10];\nint C(int n,int m){\n\tif(n&lt;0 || m&lt;0 || m>n)return 0;\n\treturn mul(fac&#91;n],mul(invfac&#91;m],invfac&#91;n-m]));\n}\nint C1(int n,int m){\n\treturn sub(C(n,m+(n-m)\/2),C(n,m+2+(n-m-2)\/2));\n}\nint T,n;\n\nvoid solve(){\n\tread(n);\n\tvector&lt;int> a(n+1),vis(n+2,0);\n\tfor(int i=1;i&lt;=n;i++)read(a&#91;i]);\n\tint mx = 0,mi = 0,cx = 0,cy = 0,ans = 0;\n\tfor(int i=1;i&lt;=n;i++){\n\t\twhile(vis&#91;mi+1])mi+=1;\n\t\tvis&#91;a&#91;i]] = 1;\n\t\tif(a&#91;i]&lt;mx &amp;&amp; a&#91;i]>mi+1){\n\t\t\tans = add(ans,C1(2*n-(cx+1),cy+1));\n\t\t\tbreak;\n\t\t}\n\t\tif(a&#91;i] == mi+1 &amp;&amp; a&#91;i]&lt;mx){\n\t\t\tans = add(ans,C1(2*n-(cx+1),cy+1));\n\t\t\tcx+=1;\n\t\t\tcy-=1;\n\t\t}else{\n\t\t\tint d = a&#91;i]-mx;\n\t\t\tans = add(ans,C1(2*n-(cx+d+1),cy+d+1));\n\t\t\tcx+=d+1;\n\t\t\tcy+=d-1;\n\t\t}\n\t\tmx = max(mx,a&#91;i]);\n\t}\n\tcout&lt;&lt;ans&lt;&lt;endl;\n}\n\nint main(){\n\tfac&#91;0] = 1;\n\tfor(int i=1;i&lt;=N;i++)fac&#91;i] = mul(fac&#91;i-1],i);\n\tinvfac&#91;N] = mpow(fac&#91;N],mod-2);\n\tfor(int i=N-1;i>=0;i--) invfac&#91;i] = mul(invfac&#91;i+1],i+1);\n\tread(T);\n\twhile(T--){\n\t\tsolve();\n\t}\n\treturn 0;\n}\n<\/code><\/pre>\n ","protected":false},"excerpt":{"rendered":"<p>\u4e00\u53e5\u8bdd\u9898\u610f\uff1a\u7ed9\u4f60\u4e00\u4e2a\u957f\u5ea6\u4e3an\u7684\u6392\u5217\uff0c\u6c42\u6709\u591a\u5c11\u957f\u5ea6\u4e3an\u7684\u6392\u5217\u4f7f\u5f97\u5192\u6ce1\u6392\u5e8f\u4ea4\u6362\u6570\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/bytew.net\/index.php?rest_route=\/wp\/v2\/posts\/365"}],"collection":[{"href":"https:\/\/bytew.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bytew.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bytew.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bytew.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=365"}],"version-history":[{"count":2,"href":"https:\/\/bytew.net\/index.php?rest_route=\/wp\/v2\/posts\/365\/revisions"}],"predecessor-version":[{"id":369,"href":"https:\/\/bytew.net\/index.php?rest_route=\/wp\/v2\/posts\/365\/revisions\/369"}],"wp:attachment":[{"href":"https:\/\/bytew.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=365"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bytew.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=365"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bytew.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=365"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}