{"id":215,"date":"2018-12-05T10:41:10","date_gmt":"2018-12-05T10:41:10","guid":{"rendered":"http:\/\/bytew.net\/?p=215"},"modified":"2021-09-08T20:20:07","modified_gmt":"2021-09-08T12:20:07","slug":"ahoi2013%e5%b7%ae%e5%bc%82","status":"publish","type":"post","link":"https:\/\/bytew.net\/?p=215","title":{"rendered":"[Ahoi2013]\u5dee\u5f02"},"content":{"rendered":"<p>\u4e00\u4e2a\u957f\u5ea6\u4e3an\u7684\u5b57\u7b26\u4e32\uff0cTi\u4ee3\u8868\u5176\u4ee5i\u5f00\u59cb\u7684\u540e\u7f00\uff0c\u6c42<\/p>\n<p><p class=\"ql-center-displayed-equation\" style=\"line-height: 55px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/bytew.net\/wp-content\/ql-cache\/quicklatex.com-064778456d28a0726dae60ef8c4a0ce8_l3.png\" height=\"55\" width=\"412\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#91;&#92;&#115;&#117;&#109;&#95;&#123;&#49;&#32;&#92;&#108;&#101;&#113;&#32;&#105;&#32;&#60;&#32;&#106;&#32;&#92;&#108;&#101;&#113;&#32;&#110;&#125;&#108;&#101;&#110;&#40;&#84;&#95;&#105;&#41;&#43;&#108;&#101;&#110;&#40;&#84;&#95;&#106;&#41;&#45;&#50;&#42;&#108;&#99;&#112;&#40;&#84;&#95;&#105;&#44;&#84;&#95;&#106;&#41;&#92;&#93;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>\n<\/p>\n<p>\u5176\u4e2dlen\u4e3a\u957f\u5ea6\uff0clcp\u4e3a\u6700\u957f\u516c\u5171\u524d\u7f00\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u8fd9\u9053\u9898\u662f\u540e\u7f00\u6570\u7ec4\u7684\u4e00\u9053\u7ecf\u5178\u9898\u3002<\/p>\n<p>\u9996\u5148\u5c06\u7b54\u6848\u8f6c\u5316\u4e3a\u4e0b\u9762\u7684\u683c\u5f0f\uff1a<\/p>\n<p><p class=\"ql-center-displayed-equation\" style=\"line-height: 55px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/bytew.net\/wp-content\/ql-cache\/quicklatex.com-a9f571e7b4064afebe86a2f0cfd743ab_l3.png\" height=\"55\" width=\"368\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#91;&#92;&#115;&#117;&#109;&#95;&#123;&#49;&#32;&#92;&#108;&#101;&#113;&#32;&#105;&#32;&#60;&#32;&#106;&#32;&#92;&#108;&#101;&#113;&#32;&#110;&#125;&#105;&#43;&#106;&#32;&#45;&#92;&#115;&#117;&#109;&#95;&#123;&#49;&#32;&#92;&#108;&#101;&#113;&#32;&#105;&#32;&#60;&#32;&#106;&#32;&#92;&#108;&#101;&#113;&#32;&#110;&#125;&#50;&#42;&#108;&#99;&#112;&#40;&#84;&#95;&#105;&#44;&#84;&#95;&#106;&#41;&#92;&#93;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>\n<\/p>\n<p>\u8fdb\u884c\u4e86\u8fd9\u4e00\u6b65\u8f6c\u5316\u4e4b\u540e\uff0c\u6211\u4eec\u53ea\u9700\u8981\u6c42\u51fa\u5b57\u7b26\u4e32\u6bcf\u5bf9\u540e\u7f00\u7684\u6700\u957f\u524d\u7f00\u5373\u53ef\u3002\u90a3\u4e48\uff0c\u8fd9\u4e2a\u53c8\u8be5\u5982\u4f55\u6c42\u5462\uff1f\u6211\u4eec\u77e5\u9053\uff0c\u4e24\u5bf9\u540e\u7f00\u7684lcp\u5c31\u662f\u5176\u5728\u9ad8\u5ea6\u6570\u7ec4\u5bf9\u5e94\u533a\u95f4\u4e2d\u7684\u6700\u5c0f\u503c\u3002\u8fd9\u4e2a\u7ed3\u8bba\u5728\u5f88\u591a\u4ecb\u7ecd\u540e\u7f00\u6570\u7ec4\u7684\u535a\u5ba2\u4e0a\u90fd\u6709\u8bc1\u660e\uff0c\u8fd9\u91cc\u4e0d\u505a\u8bf4\u660e\u3002\u8fd9\u6837\u7684\u8bdd\uff0c\u6211\u4eec\u53ea\u9700\u8981\u7edf\u8ba1\u51fa\u9ad8\u5ea6\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u6570\u5728\u54ea\u4e00\u6bb5\u533a\u95f4\u4e2d\u662f\u6700\u5c0f\u503c\u5373\u53ef\u3002\u8fd9\u4e2a\u95ee\u9898\u53ef\u4ee5\u4f7f\u7528\u5355\u8c03\u6808\u5f97\u4ee5\u89e3\u51b3\u3002<\/p>\n<p>\u8fd9\u6837\u53c8\u5e26\u6765\u4e86\u4e00\u4e2a\u53bb\u91cd\u7684\u95ee\u9898\uff0c\u5c31\u662f\u4e00\u4e2a\u533a\u95f4\u5185\u7684\u6700\u5c0f\u503c\u53ef\u80fd\u6709\u82e5\u5e72\u4e2a\u3002\u8fd9\u4e2a\u95ee\u9898\u6709\u4e00\u4e2a\u7b80\u4fbf\u7684\u89e3\u6cd5\uff1a\u53ea\u9700\u5c06\u6bcf\u4e2a\u6570\u6240\u505a\u4e3a\u6700\u5c0f\u503c\u7684\u533a\u95f4\u5de6\u7aef\u70b9\u8bbe\u4e3a\u4e25\u683c\u5927\u4e8e\u5b83\u7684\u7b2c\u4e00\u4e2a\u6570\uff0c\u800c\u53f3\u7aef\u70b9\u662f\u4e0d\u4e25\u683c\u5927\u4e8e\u5b83\u7684\u7b2c\u4e00\u4e2a\u6570\u5c31\u884c\u4e86\u3002<\/p>\n<p>\u4e0b\u9644\u4ee3\u7801<\/p>\n<pre class=\"theme:obsidian lang:c++ decode:true \">#include &lt;cstdio&gt;\n#include &lt;cstring&gt;\n#include &lt;iostream&gt;\n#define N 1000010\n#define rep(i,l,r) for(int i=l;i&lt;=r;i++)\n#define rrep(i,r,l) for(int i=r;i&gt;=l;i--)\nusing namespace std;\ntypedef long long ll;\nint t1[N],t2[N],sa[N],h[N],rk[N],c[10*N],a[N],m,n;\nchar s[N];\nvoid calcsa(int n,int m){\n\tint *x = t1,*y = t2,p = 0,f = 0;\n\tmemset(c,0,4*m+40);\n\trep(i,1,n)c[x[i]=a[i]]++;\n\trep(i,1,m)c[i]+=c[i-1];\n\trrep(i,n,1)sa[c[x[i]]--]=i;\n\tfor(int i=1;i&lt;=n&amp;&amp;p&lt;=n;i*=2){\n\t\tp=0;\n\t\trep(j,n-i+1,n)y[++p]=j;\n\t\trep(j,1,n)if(sa[j]&gt;i)y[++p]=sa[j]-i;\n\t\tmemset(c,0,4*m+40);\n\t\trep(j,1,n)c[x[y[j]]]++;\n\t\trep(j,1,m)c[j]+=c[j-1];\n\t\trrep(j,n,1)sa[c[x[y[j]]]--]=y[j];\n\t\tswap(x,y);x[sa[1]]=1;p=2;\n\t\trep(j,2,n)x[sa[j]]=y[sa[j]]==y[sa[j-1]]&amp;&amp;y[sa[j]+i]==y[sa[j-1]+i]?p-1:p++;\n\t\tm=p;\n\t}\n\trep(i,1,n)rk[sa[i]]=i;\n\trep(i,1,n){\n\t\tint j=sa[rk[i]-1];\n\t\tif(f)f--;while(a[i+f]==a[j+f])f++;\n\t\th[rk[i]]=f;\n\t}\n}\nint st[N],stn = 0,l[N],r[N];\nint main(){\n\tios::sync_with_stdio(false);\n\tcin.tie(0);\n    cin&gt;&gt;s;\n    int len=strlen(s);\n    for(int i=0;i&lt;len;i++)a[++n]=s[i]-' ';\n    calcsa(n,10000);\n\tll ans = 0;\n\tfor(int i=1;i&lt;=n;i++) ans+=1ll*i*(i-1)+1ll*i*(i-1)\/2;\n\th[1] = h[n+1] = -1;\n\tst[0] = 1;stn=1;\n\tfor(int i=2;i&lt;=n;i++){\n\t\twhile(h[st[stn-1]]&gt;h[i])stn--;\n\t\tl[i] = st[stn-1];\n\t\tst[stn] = i;\n\t\tstn++;\n\t}\n\tst[0] = n+1;stn=1;\n\tfor(int i=n;i&gt;=2;i--){\n\t\twhile(h[st[stn-1]]&gt;=h[i])stn--;\n\t\tr[i] = st[stn-1];\n\t\tst[stn] = i;\n\t\tstn++;\n\t}\n\tfor(int i=2;i&lt;=n;i++)ans-=2ll*h[i]*(r[i]-i)*(i-l[i]);\n\tcout&lt;&lt;ans&lt;&lt;endl;\n\treturn 0;\n}\n<\/pre>\n<p>&nbsp;<\/p>\n ","protected":false},"excerpt":{"rendered":"<p>\u4e00\u4e2a\u957f\u5ea6\u4e3an\u7684\u5b57\u7b26\u4e32\uff0cTi\u4ee3\u8868\u5176\u4ee5i\u5f00\u59cb\u7684\u540e\u7f00\uff0c\u6c42 &nbsp; &nbsp; \u5176\u4e2dlen\u4e3a\u957f\u5ea6\uff0clcp\u4e3a\u6700\u957f [&hellip;]<\/p>\n","protected":false},"author":2,"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\/215"}],"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\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bytew.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=215"}],"version-history":[{"count":1,"href":"https:\/\/bytew.net\/index.php?rest_route=\/wp\/v2\/posts\/215\/revisions"}],"predecessor-version":[{"id":755,"href":"https:\/\/bytew.net\/index.php?rest_route=\/wp\/v2\/posts\/215\/revisions\/755"}],"wp:attachment":[{"href":"https:\/\/bytew.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bytew.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bytew.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}