{"id":306,"date":"2017-12-22T19:42:04","date_gmt":"2017-12-22T11:42:04","guid":{"rendered":"http:\/\/kylelv.com\/?p=306"},"modified":"2017-12-22T19:42:19","modified_gmt":"2017-12-22T11:42:19","slug":"bzoj-2089-2090-poi2010monotonicity-2-%e7%ba%bf%e6%ae%b5%e6%a0%91%e4%bc%98%e5%8c%96dp","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=306","title":{"rendered":"bzoj 2089\/2090: [Poi2010]Monotonicity 2  &#8212; \u7ebf\u6bb5\u6811\u4f18\u5316dp"},"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-69fdef3f481b9\" 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-69fdef3f481b9\"  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=306\/#2090_Poi2010Monotonicity_2\" title=\"2090: [Poi2010]Monotonicity 2\">2090: [Poi2010]Monotonicity 2<\/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=306\/#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=306\/#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=306\/#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=306\/#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=306\/#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=306\/#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=306\/#Source\" title=\"Source\">Source<\/a><\/li><\/ul><\/nav><\/div>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"2090_Poi2010Monotonicity_2\"><\/span>2090: [Poi2010]Monotonicity 2<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: center;\"><span class=\"green\">Time Limit:\u00a0<\/span>30 Sec\u00a0\u00a0<span class=\"green\">Memory Limit:\u00a0<\/span>259 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<p>\u7ed9\u51faN\u4e2a\u6b63\u6574\u6570a[1..N]\uff0c\u518d\u7ed9\u51faK\u4e2a\u5173\u7cfb\u7b26\u53f7\uff08&gt;\u3001&lt;\u6216=\uff09s[1..k]\u3002<br \/>\n\u9009\u51fa\u4e00\u4e2a\u957f\u5ea6\u4e3aL\u7684\u5b50\u5e8f\u5217\uff08\u4e0d\u8981\u6c42\u8fde\u7eed\uff09\uff0c\u8981\u6c42\u8fd9\u4e2a\u5b50\u5e8f\u5217\u7684\u7b2ci\u9879\u548c\u7b2ci+1\u9879\u7684\u7684\u5927\u5c0f\u5173\u7cfb\u4e3as[(i-1)mod K+1]\u3002<br \/>\n\u6c42\u51faL\u7684\u6700\u5927\u503c\u3002<\/p>\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<p>\u7b2c\u4e00\u884c\u4e24\u4e2a\u6b63\u6574\u6570\uff0c\u5206\u522b\u8868\u793aN\u548cK (N, K &lt;= 500,000)\u3002<br \/>\n\u7b2c\u4e8c\u884c\u7ed9\u51faN\u4e2a\u6b63\u6574\u6570\uff0c\u7b2ci\u4e2a\u6b63\u6574\u6570\u8868\u793aa[i] (a[i] &lt;= 10^6)\u3002<br \/>\n\u7b2c\u4e09\u884c\u7ed9\u51faK\u4e2a\u7a7a\u683c\u9694\u5f00\u5173\u7cfb\u7b26\u53f7\uff08&gt;\u3001&lt;\u6216=\uff09\uff0c\u7b2ci\u4e2a\u8868\u793as[i]\u3002<\/p>\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>\u4e00\u4e2a\u6b63\u6574\u6570\uff0c\u8868\u793aL\u7684\u6700\u5927\u503c\u3002<\/p>\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\"><span class=\"sampledata\">7 3<br \/>\n2 4 3 1 3 5 3<br \/>\n&lt; &gt; =<\/span><\/span>&nbsp;<\/p>\n<\/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\">\n<p><span class=\"sampledata\">6<\/span><\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"HINT\"><\/span>HINT<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p>\u9009\u51fa\u7684\u5b50\u5e8f\u5217\u4e3a2 4 3 3 5 3\uff0c\u76f8\u90bb\u5927\u5c0f\u5173\u7cfb\u5206\u522b\u662f&lt; &gt; = &lt; &gt;\u3002<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Source\"><\/span>Source<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u5f88\u597d\u73a9\u7684\u65b9\u5f0f<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u8003\u8651dp\uff0c\u7528f[i]\u8868\u793a\u5230\u7b2ci\u4f4d\u65f6\u7684\u6700\u957f\u957f\u5ea6<\/p>\n<p>\u6240\u4ee5\u8fd9\u4e2a\u65f6\u5019\u4ed6\u8fde\u63a5\u4e0b\u4e00\u4f4d\u7684\u7b26\u53f7\u662f\u56fa\u5b9a\u7684<\/p>\n<p>\u8fd9\u6837\u6211\u4eec\u5c31\u53ef\u4ee5\u5206\u4e09\u7c7b\uff1a<\/p>\n<p>\u5982\u679c\u662f=\uff0c\u5c31\u5f00\u4e00\u4e2a\u6876\u8bb0\u5f55\u4e00\u4e0b\u503c\u4e3a\u8fd9\u4e2a\u662f\u7684\u5f53\u524d\u6700\u4f18\u89e3<\/p>\n<p>\u5982\u679c\u662f&lt;\uff0c\u6211\u4eec\u53ef\u4ee5\u63a8\u5165\u4e00\u4e2a\u4e0b\u4e00\u4f4d\u662f\u5c0f\u4e8e\u53f7\u7684\u7ebf\u6bb5\u6811\uff0c\u4ee5\u6743\u503c\u4e3a\u4e0b\u8868\uff0c\u7ef4\u62a4f\u503c<\/p>\n<p>\u7136\u540e\u4e0b\u6b21\u66f4\u65b0f\u7684\u65f6\u5019\uff0c\u53d6\u51fa\u5408\u6cd5\u533a\u95f4\u7684\u6700\u5927\u7684\u503c\u5c31\u597d\u4e86<\/p>\n<p>\u5982\u679c\u662f&gt;\uff0c\u540c\u7406\u53ef\u4ee5\u7ef4\u62a4\u4e00\u4e2a\u4e0b\u4e00\u4f4d\u662f\u5c0f\u4e8e\u53f7\u7684\u7ebf\u6bb5\u6811<\/p>\n<p>\u8fd9\u6837\u5c31\u53ef\u4ee5\u505a\u5230\u65f6\u95f4\u590d\u6742\u5ea6O(nlogn)\u4e86<\/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 1000010\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,k,nn,a[N],op[N],f[N],ans;\r\nstruct segtr\r\n{\r\n\t#define ls p&lt;&lt;1\r\n\t#define rs p&lt;&lt;1|1\r\n\tint mx[N&lt;&lt;2];\r\n\tvoid xg(int p,int l,int r,int x,int v)\r\n\t{\r\n\t\tif(l==r){mx[p]=v;return;}\r\n\t\tint mid=l+r&gt;&gt;1;\r\n\t\tx&lt;=mid?xg(ls,l,mid,x,v):xg(rs,mid+1,r,x,v);\r\n\t\tmx[p]=max(mx[ls],mx[rs]);\r\n\t}\r\n\tint fd(int p,int l,int r,int L,int R)\r\n\t{\r\n\t\tif(L&gt;R) return 0;\r\n\t\tif(l==L&amp;&amp;R==r) return mx[p];\r\n\t\tint mid=l+r&gt;&gt;1;\r\n\t\tif(R&lt;=mid) return fd(ls,l,mid,L,R);\r\n\t\tif(L&gt;mid) return fd(rs,mid+1,r,L,R);\r\n\t\treturn max(fd(ls,l,mid,L,mid),fd(rs,mid+1,r,mid+1,R));\r\n\t}\r\n}tr[2];\r\nint ji[N];\r\nint main()\r\n{\r\n\tn=rd();k=rd();\r\n\tfor(int i=1;i&lt;=n;i++) a[i]=rd(),nn=max(a[i],nn);\r\n\tchar ch[5];\r\n\tfor(int i=1;i&lt;=k;i++)\r\n\t{\r\n\t\tscanf(\"%s\",ch);\r\n\t\tif(ch[0]=='&gt;') op[i]=0;\r\n\t\telse if(ch[0]=='&lt;') op[i]=1;\r\n\t\telse op[i]=2;\r\n    }\r\n\tfor(int i=1,tt;i&lt;=n;i++)\r\n\t{\r\n\t\ttt=max(tr[0].fd(1,1,nn,a[i]+1,nn),tr[1].fd(1,1,nn,1,a[i]-1));\r\n\t\tf[i]=max(tt,ji[a[i]])+1;\r\n\t\tans=max(ans,f[i]);\r\n\t\ttt=op[(f[i]-1)%k+1];\r\n\t\tif(tt==2) ji[a[i]]=max(f[i],ji[a[i]]);\r\n\t\telse tr[tt].xg(1,1,nn,a[i],f[i]);\r\n\t}\r\n\tprintf(\"%d\\n\",ans);\r\n\treturn 0;\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; 2090: [Poi2010]Monotonicity 2 Time Limit:\u00a030 Sec [&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":[5,10],"class_list":["post-306","post","type-post","status-publish","format-standard","hentry","category-bzoj","tag-dp","tag-10"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/306","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=306"}],"version-history":[{"count":2,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/306\/revisions"}],"predecessor-version":[{"id":308,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/306\/revisions\/308"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}