{"id":515,"date":"2017-04-27T20:18:49","date_gmt":"2017-04-27T12:18:49","guid":{"rendered":"http:\/\/kylelv.com\/?p=515"},"modified":"2018-01-18T17:13:08","modified_gmt":"2018-01-18T09:13:08","slug":"bzoj-3585-mex-3339-rmq-problem-%e4%b8%bb%e5%b8%ad%e6%a0%91","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=515","title":{"rendered":"bzoj 3585: mex &#038;&#038; 3339: Rmq Problem  &#8212; \u4e3b\u5e2d\u6811"},"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-69fdef43f118e\" 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-69fdef43f118e\"  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=515\/#3585_mex\" title=\"3585: mex\">3585: mex<\/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=515\/#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=515\/#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=515\/#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=515\/#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=515\/#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=515\/#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=515\/#Source\" title=\"Source\">Source<\/a><\/li><\/ul><\/nav><\/div>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"3585_mex\"><\/span>3585: mex<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: center;\"><span class=\"green\">Time Limit:\u00a020 Sec\u00a0\u00a0Memory Limit:\u00a0128 MB<\/span><\/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>\u3000\u3000\u6709\u4e00\u4e2a\u957f\u5ea6\u4e3an\u7684\u6570\u7ec4{a1,a2,&#8230;,an}\u3002m\u6b21\u8be2\u95ee\uff0c\u6bcf\u6b21\u8be2\u95ee\u4e00\u4e2a\u533a\u95f4\u5185\u6700\u5c0f\u6ca1\u6709\u51fa\u73b0\u8fc7\u7684\u81ea\u7136\u6570\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>\u3000\u3000\u7b2c\u4e00\u884cn,m\u3002<br \/>\n\u7b2c\u4e8c\u884c\u4e3an\u4e2a\u6570\u3002<br \/>\n\u4ece\u7b2c\u4e09\u884c\u5f00\u59cb\uff0c\u6bcf\u884c\u4e00\u4e2a\u8be2\u95eel,r\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>\u3000\u3000\u4e00\u884c\u4e00\u4e2a\u6570\uff0c\u8868\u793a\u6bcf\u4e2a\u8be2\u95ee\u7684\u7b54\u6848\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\">5 5<br \/>\n2 1 0 2 1<br \/>\n3 3<br \/>\n2 3<br \/>\n2 4<br \/>\n1 2<br \/>\n3 5<br \/>\n<\/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 \/>\n2<br \/>\n3<br \/>\n0<br \/>\n3<br \/>\n<\/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\">\n<p>&nbsp;<\/p>\n<p>\u6570\u636e\u89c4\u6a21\u548c\u7ea6\u5b9a<\/p>\n<p>\u5bf9\u4e8e100%\u7684\u6570\u636e\uff1a<\/p>\n<p>1&lt;=n,m&lt;=200000<\/p>\n<p>0&lt;=ai&lt;=109<\/p>\n<p>1&lt;=l&lt;=r&lt;=n<\/p>\n<p>\u5bf9\u4e8e30%\u7684\u6570\u636e\uff1a<\/p>\n<p>1&lt;=n,m&lt;=1000<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Source\"><\/span>Source<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p><a href=\"http:\/\/www.lydsy.com\/JudgeOnline\/problemset.php?search=By%20%E4%BD%9A%E5%90%8D%E6%8F%90%E4%BE%9B\" target=\"_blank\" rel=\"noopener\">By \u4f5a\u540d\u63d0\u4f9b<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>\u6211\u4eec\u8003\u8651\u5efa\u6743\u503c\u7ebf\u6bb5\u6811\uff0c\u6bcf\u4e2a\u6570\u5b57 x \u4fdd\u5b58\u5b83\u6700\u540e\u51fa\u73b0\u7684\u4f4d\u7f6e<\/p>\n<p>\u8fd9\u6837\u67e5\u8be2[l,r]\uff0c\u5c31\u662f\u627e\u7b2cr\u68f5\u4e3b\u5e2d\u6811\u4e2d\u7b2c\u4e00\u4e2a\u503c&lt; l \u7684<\/p>\n<p>\u4e3b\u5e2d\u6811\u4e0a\u6bcf\u4e2a\u533a\u95f4\u7ef4\u62a4\u5f53\u524d\u6570\u4e2d\uff0c\u6743\u503c\u4ece l \u5230 r \u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u6700\u9760\u5de6\u7684\u4f4d\u7f6e<\/p>\n<p>\u5c31\u662f\u76f8\u5f53\u4e8e\u7ef4\u62a4\u533a\u95f4\u6700\u5c0f\u503c\u5373\u53ef<\/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 ll long long\r\n#define N 200010\r\n#define M 6000100\r\ninline int read()\r\n{\r\n    int x=0,f=1;char ch=getchar();\r\n    while(ch&lt;'0'||ch&gt;'9'){if(ch=='-')f=-1;ch=getchar();}\r\n    while(ch&gt;='0'&amp;&amp;ch&lt;='9'){x=x*10+ch-'0';ch=getchar();}\r\n    return x*f;\r\n}\r\nint rt[N],ls[M],rs[M],mn[M],cnt;\r\nvoid add(int &amp;p,int f,int l,int r,int x,int v)\r\n{\r\n    p=++cnt;\r\n    if(l==r){mn[p]=v;return;}\r\n    ls[p]=ls[f];rs[p]=rs[f];\r\n    int mid=(l+r)&gt;&gt;1;\r\n    if(x&gt;mid) add(rs[p],rs[f],mid+1,r,x,v);\r\n    else add(ls[p],ls[f],l,mid,x,v);\r\n    mn[p]=min(mn[ls[p]],mn[rs[p]]);\r\n}\r\nint query(int p,int l,int r,int v)\r\n{\r\n    if(l==r) return l;\r\n    int mid=(l+r)&gt;&gt;1;\r\n    if(mn[ls[p]]&lt;v) return query(ls[p],l,mid,v);\r\n    else return query(rs[p],mid+1,r,v);\r\n}\r\nint n,m,x,mx=1e8+5;\r\nint main()\r\n{\r\n    n=read();m=read();\r\n    for(int i=1;i&lt;=n;i++){x=read();add(rt[i],rt[i-1],0,mx,x,i);}\r\n    int l,r;\r\n    for(int i=1;i&lt;=m;i++)\r\n    {\r\n        l=read();r=read();\r\n        printf(\"%d\\n\",query(rt[r],0,mx,l));\r\n    }\r\n    return 0;\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; 3585: mex Time Limit:\u00a020 Sec\u00a0\u00a0Memory Limit:\u00a0128  [&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":[35],"class_list":["post-515","post","type-post","status-publish","format-standard","hentry","category-bzoj","tag-35"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/515","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=515"}],"version-history":[{"count":2,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/515\/revisions"}],"predecessor-version":[{"id":517,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/515\/revisions\/517"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=515"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=515"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=515"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}