{"id":478,"date":"2018-01-04T20:20:52","date_gmt":"2018-01-04T12:20:52","guid":{"rendered":"http:\/\/kylelv.com\/?p=478"},"modified":"2018-01-16T20:55:21","modified_gmt":"2018-01-16T12:55:21","slug":"bzoj-4516-sdoi2016%e7%94%9f%e6%88%90%e9%ad%94%e5%92%92-%e5%90%8e%e7%bc%80%e8%87%aa%e5%8a%a8%e6%9c%ba","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=478","title":{"rendered":"bzoj 4516: [Sdoi2016]\u751f\u6210\u9b54\u5492  &#8212; \u540e\u7f00\u81ea\u52a8\u673a"},"content":{"rendered":"<p>&nbsp;<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_73 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69fdef4458dd6\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69fdef4458dd6\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.kylelv.com\/?p=478\/#4516_Sdoi2016%E7%94%9F%E6%88%90%E9%AD%94%E5%92%92\" title=\"4516: [Sdoi2016]\u751f\u6210\u9b54\u5492\">4516: [Sdoi2016]\u751f\u6210\u9b54\u5492<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.kylelv.com\/?p=478\/#Description\" title=\"Description\">Description<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blog.kylelv.com\/?p=478\/#Input\" title=\"Input\">Input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blog.kylelv.com\/?p=478\/#Output\" title=\"Output\">Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blog.kylelv.com\/?p=478\/#Sample_Input\" title=\"Sample Input\">Sample Input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blog.kylelv.com\/?p=478\/#Sample_Output\" title=\"Sample Output\">Sample Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blog.kylelv.com\/?p=478\/#HINT\" title=\"HINT\">HINT<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blog.kylelv.com\/?p=478\/#Source\" title=\"Source\">Source<\/a><\/li><\/ul><\/nav><\/div>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"4516_Sdoi2016%E7%94%9F%E6%88%90%E9%AD%94%E5%92%92\"><\/span>4516: [Sdoi2016]\u751f\u6210\u9b54\u5492<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: center;\"><span class=\"green\">Time Limit:\u00a0<\/span>10 Sec\u00a0\u00a0<span class=\"green\">Memory Limit:\u00a0<\/span>128 MB<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Description\"><\/span>Description<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<div>\u9b54\u5492\u4e32\u7531\u8bb8\u591a\u9b54\u5492\u5b57\u7b26\u7ec4\u6210\uff0c\u9b54\u5492\u5b57\u7b26\u53ef\u4ee5\u7528\u6570\u5b57\u8868\u793a\u3002\u4f8b\u5982\u53ef\u4ee5\u5c06\u9b54\u5492\u5b57\u7b26 1\u30012 \u62fc\u51d1\u8d77\u6765\u5f62\u6210\u4e00\u4e2a\u9b54\u5492\u4e32 [1,2]\u3002<\/div>\n<div>\u4e00\u4e2a\u9b54\u5492\u4e32 S \u7684\u975e\u7a7a\u5b57\u4e32\u88ab\u79f0\u4e3a\u9b54\u5492\u4e32 S \u7684\u751f\u6210\u9b54\u5492\u3002<\/div>\n<div>\u4f8b\u5982 S=[1,2,1] \u65f6\uff0c\u5b83\u7684\u751f\u6210\u9b54\u5492\u6709 [1]\u3001[2]\u3001[1,2]\u3001[2,1]\u3001[1,2,1] \u4e94\u79cd\u3002S=[1,1,1] \u65f6\uff0c\u5b83\u7684\u751f\u6210\u9b54\u5492\u6709 [1]\u3001<\/div>\n<div>[1,1]\u3001[1,1,1] \u4e09\u79cd\u3002\u6700\u521d S \u4e3a\u7a7a\u4e32\u3002\u5171\u8fdb\u884c n \u6b21\u64cd\u4f5c\uff0c\u6bcf\u6b21\u64cd\u4f5c\u662f\u5728 S \u7684\u7ed3\u5c3e\u52a0\u5165\u4e00\u4e2a\u9b54\u5492\u5b57\u7b26\u3002\u6bcf\u6b21\u64cd\u4f5c\u540e\u90fd<\/div>\n<div>\u9700\u8981\u6c42\u51fa\uff0c\u5f53\u524d\u7684\u9b54\u5492\u4e32 S \u5171\u6709\u591a\u5c11\u79cd\u751f\u6210\u9b54\u5492\u3002<\/div>\n<div><\/div>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Input\"><\/span>Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<div>\u7b2c\u4e00\u884c\u4e00\u4e2a\u6574\u6570 n\u3002<\/div>\n<div>\u7b2c\u4e8c\u884c n \u4e2a\u6570\uff0c\u7b2c i \u4e2a\u6570\u8868\u793a\u7b2c i \u6b21\u64cd\u4f5c\u52a0\u5165\u7684\u9b54\u5492\u5b57\u7b26\u3002<\/div>\n<div>1\u2264n\u2264100000\u3002,\u7528\u6765\u8868\u793a\u9b54\u5492\u5b57\u7b26\u7684\u6570\u5b57 x \u6ee1\u8db3 1\u2264x\u226410^9<\/div>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Output\"><\/span>Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p>\u8f93\u51fa n \u884c\uff0c\u6bcf\u884c\u4e00\u4e2a\u6570\u3002\u7b2c i \u884c\u7684\u6570\u8868\u793a\u7b2c i \u6b21\u64cd\u4f5c\u540e S \u7684\u751f\u6210\u9b54\u5492\u6570\u91cf<\/p>\n<div><\/div>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Sample_Input\"><\/span>Sample Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\"><span class=\"sampledata\">7<br \/>\n1 2 3 3 3 1 2<\/span><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Sample_Output\"><\/span>Sample Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\"><span class=\"sampledata\">1<br \/>\n3<br \/>\n6<br \/>\n9<br \/>\n12<br \/>\n17<br \/>\n22<\/span><\/div>\n<h2><span class=\"ez-toc-section\" id=\"HINT\"><\/span>HINT<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\"><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Source\"><\/span>Source<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u677f\u5b50\u9898\u3002\u3002\u3002<\/p>\n<pre class=\"lang:c++ decode:true \">#include&lt;map&gt;\r\n#include&lt;cmath&gt;\r\n#include&lt;queue&gt;\r\n#include&lt;cstdio&gt;\r\n#include&lt;cstring&gt;\r\n#include&lt;iostream&gt;\r\n#include&lt;algorithm&gt;\r\nusing namespace std;\r\n#define inf 1000000007\r\n#define ll long long\r\n#define N 200010\r\ninline int rd()\r\n{\r\n\tint x=0,f=1;char ch=getchar();\r\n\twhile(ch&lt;'0'||ch&gt;'9'){if(ch=='-')f=-1;ch=getchar();}\r\n\twhile(ch&gt;='0'&amp;&amp;ch&lt;='9'){x=x*10+ch-'0';ch=getchar();}\r\n\treturn x*f;\r\n}\r\nint n;\r\nll ans;\r\nint fa[N],l[N],lst,cnt;\r\nmap&lt;int,int&gt;c[N];\r\nvoid ins(int x)\r\n{\r\n\tint p,q,np,nq;\r\n\tp=lst;np=lst=++cnt;\r\n\tl[np]=l[p]+1;\r\n\twhile(!c[p][x]&amp;&amp;p) c[p][x]=np,p=fa[p];\r\n\tif(!p) fa[np]=1;\r\n\telse \r\n\t{\r\n\t\tq=c[p][x];\r\n\t\tif(l[q]==l[p]+1) fa[np]=q;\r\n\t\telse \r\n\t\t{\r\n\t\t\tnq=++cnt;l[nq]=l[p]+1;\r\n\t\t\tc[nq]=c[q];\r\n\t\t\tfa[nq]=fa[q];\r\n\t\t\tfa[q]=fa[np]=nq;\r\n\t\t\twhile(c[p][x]==q) c[p][x]=nq,p=fa[p];\r\n\t\t}\r\n\t}\r\n\tans+=l[np]-l[fa[np]];\r\n}\r\nint main()\r\n{\r\n\tn=rd();\r\n\tlst=cnt=1;\r\n\tfor(int i=1,x;i&lt;=n;i++)\r\n\t{\r\n\t\tx=rd();\r\n\t\tins(x);\r\n\t\tprintf(\"%lld\\n\",ans);\r\n\t}\r\n\treturn 0;\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; 4516: [Sdoi2016]\u751f\u6210\u9b54\u5492 Time Limit:\u00a010 Sec\u00a0\u00a0Memory  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[49],"class_list":["post-478","post","type-post","status-publish","format-standard","hentry","category-bzoj","tag-49"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/478","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=478"}],"version-history":[{"count":2,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/478\/revisions"}],"predecessor-version":[{"id":480,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/478\/revisions\/480"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}