{"id":375,"date":"2017-03-01T19:45:13","date_gmt":"2017-03-01T11:45:13","guid":{"rendered":"http:\/\/kylelv.com\/?p=375"},"modified":"2017-12-28T14:45:22","modified_gmt":"2017-12-28T06:45:22","slug":"3524-poi2014couriers-%e4%b8%bb%e5%b8%ad%e6%a0%91","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=375","title":{"rendered":"3524: [Poi2014]Couriers  &#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-69fdef1cab573\" 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-69fdef1cab573\"  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=375\/#3524_Poi2014Couriers\" title=\"3524: [Poi2014]Couriers\">3524: [Poi2014]Couriers<\/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=375\/#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=375\/#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=375\/#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=375\/#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=375\/#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=375\/#HINT\" title=\"HINT\">HINT<\/a><\/li><\/ul><\/nav><\/div>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"3524_Poi2014Couriers\"><\/span>3524: [Poi2014]Couriers<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: center;\"><span class=\"green\">Time Limit: 20 Sec\u00a0\u00a0Memory Limit: 256 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>\u7ed9\u4e00\u4e2a\u957f\u5ea6\u4e3an\u7684\u5e8f\u5217a\u30021\u2264a[i]\u2264n\u3002<br \/>\nm\u7ec4\u8be2\u95ee\uff0c\u6bcf\u6b21\u8be2\u95ee\u4e00\u4e2a\u533a\u95f4[l,r]\uff0c\u662f\u5426\u5b58\u5728\u4e00\u4e2a\u6570\u5728[l,r]\u4e2d\u51fa\u73b0\u7684\u6b21\u6570\u5927\u4e8e(r-l+1)\/2\u3002\u5982\u679c\u5b58\u5728\uff0c\u8f93\u51fa\u8fd9\u4e2a\u6570\uff0c\u5426\u5219\u8f93\u51fa0\u3002<\/p>\n<p>&nbsp;<\/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\u6570n\uff0cm\u3002<br \/>\n\u7b2c\u4e8c\u884cn\u4e2a\u6570\uff0ca[i]\u3002<br \/>\n\u63a5\u4e0b\u6765m\u884c\uff0c\u6bcf\u884c\u4e24\u4e2a\u6570l,r\uff0c\u8868\u793a\u8be2\u95ee[l,r]\u8fd9\u4e2a\u533a\u95f4\u3002<\/p>\n<p>&nbsp;<\/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>m\u884c\uff0c\u6bcf\u884c\u5bf9\u5e94\u4e00\u4e2a\u7b54\u6848\u3002<\/p>\n<p>&nbsp;<\/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 5<br \/>\n1 1 3 2 3 4 3<br \/>\n1 3<br \/>\n1 4<br \/>\n3 7<br \/>\n1 7<br \/>\n6 6<\/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\"><span class=\"sampledata\"><span class=\"sampledata\">1<br \/>\n0<br \/>\n3<br \/>\n0<br \/>\n4<\/span><\/span>&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>&nbsp;<\/p>\n<p>\u3010\u6570\u636e\u8303\u56f4\u3011<\/p>\n<p>n,m\u2264500000<\/p>\n<pre class=\"lang:c++ decode:true \">#include&lt;cstdio&gt;\r\n#define N 10000010\r\n#define M 500010\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 n,m,sz,rt[M],ls[N],rs[N],sum[N];\r\ninline void add(int l,int r,int a,int &amp;p,int v)\r\n{\r\n    p=++sz;sum[p]=sum[a]+1;\r\n    if(l==r)return;\r\n    ls[p]=ls[a];rs[p]=rs[a];\r\n    int mid=(l+r)&gt;&gt;1;\r\n    if(v&lt;=mid) add(l,mid,ls[a],ls[p],v);\r\n    else add(mid+1,r,rs[a],rs[p],v);\r\n}\r\ninline int qwq(int L,int R)\r\n{\r\n    int x=rt[L-1],y=rt[R],md=(R-L+1)&gt;&gt;1,l=1,r=n,mid;\r\n    while(l&lt;r)\r\n    {\r\n        if(sum[y]-sum[x]&lt;=md) return 0;\r\n        mid=(l+r)&gt;&gt;1;\r\n        if(sum[ls[y]]-sum[ls[x]]&gt;md){r=mid;x=ls[x];y=ls[y];}\r\n        else if(sum[rs[y]]-sum[rs[x]]&gt;md){l=mid+1;x=rs[x];y=rs[y];}\r\n        else return 0;\r\n    }\r\n    return l;\r\n}\r\nint x,l,r;\r\nint main()\r\n{\r\n    n=read();m=read();\r\n    for(int i=1;i&lt;=n;i++)\r\n    {\r\n        x=read();\r\n        add(1,n,rt[i-1],rt[i],x);\r\n    }\r\n    while(m--)\r\n    {\r\n        l=read();r=read();\r\n        printf(\"%d\\n\",qwq(l,r));\r\n    }\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; 3524: [Poi2014]Couriers Time Limit: 20 Sec\u00a0\u00a0Memo [&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-375","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\/375","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=375"}],"version-history":[{"count":2,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/375\/revisions"}],"predecessor-version":[{"id":377,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/375\/revisions\/377"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}