{"id":340,"date":"2017-01-17T14:24:59","date_gmt":"2017-01-17T06:24:59","guid":{"rendered":"http:\/\/kylelv.com\/?p=340"},"modified":"2017-12-25T20:36:58","modified_gmt":"2017-12-25T12:36:58","slug":"bzoj-1651-usaco2006-febstall-reservations-%e4%b8%93%e7%94%a8%e7%89%9b%e6%a3%9a-%e7%ba%bf%e6%ae%b5%e6%a0%91","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=340","title":{"rendered":"bzoj 1651: [Usaco2006 Feb]Stall Reservations \u4e13\u7528\u725b\u68da  &#8212; \u7ebf\u6bb5\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-69fdef44847e5\" 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-69fdef44847e5\"  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=340\/#1651_Usaco2006_FebStall_Reservations_%E4%B8%93%E7%94%A8%E7%89%9B%E6%A3%9A\" title=\"1651: [Usaco2006 Feb]Stall Reservations \u4e13\u7528\u725b\u68da\">1651: [Usaco2006 Feb]Stall Reservations \u4e13\u7528\u725b\u68da<\/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=340\/#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=340\/#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=340\/#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=340\/#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=340\/#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=340\/#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=340\/#Source\" title=\"Source\">Source<\/a><\/li><\/ul><\/nav><\/div>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"1651_Usaco2006_FebStall_Reservations_%E4%B8%93%E7%94%A8%E7%89%9B%E6%A3%9A\"><\/span>1651: [Usaco2006 Feb]Stall Reservations \u4e13\u7528\u725b\u68da<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: center;\"><span class=\"green\">Time Limit:\u00a010 Sec\u00a0\u00a0Memory Limit:\u00a064 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>Oh those picky N (1 &lt;= N &lt;= 50,000) cows! They are so picky that each one will only be milked over some precise time interval A..B (1 &lt;= A &lt;= B &lt;= 1,000,000), which includes both times A and B. Obviously, FJ must create a reservation system to determine which stall each cow can be assigned for her milking time. Of course, no cow will share such a private moment with other cows. Help FJ by determining: * The minimum number of stalls required in the barn so that each cow can have her private milking period * An assignment of cows to these stalls over time<\/p>\n<p>\u6709N\u5934\u725b,\u6bcf\u5934\u725b\u6709\u4e2a\u559d\u6c34\u65f6\u95f4,\u8fd9\u6bb5\u65f6\u95f4\u5b83\u5c06\u4e13\u7528\u4e00\u4e2aStall \u73b0\u5728\u7ed9\u51fa\u6bcf\u5934\u725b\u7684\u559d\u6c34\u65f6\u95f4\u6bb5,\u95ee\u81f3\u5c11\u8981\u591a\u5c11\u4e2aStall\u624d\u80fd\u6ee1\u8db3\u5b83\u4eec\u7684\u8981\u6c42<\/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>* Line 1: A single integer, N<\/p>\n<p>* Lines 2..N+1: Line i+1 describes cow i&#8217;s milking interval with two space-separated integers.<\/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>* Line 1: The minimum number of stalls the barn must have.<\/p>\n<p>* Lines 2..N+1: Line i+1 describes the stall to which cow i will be assigned for her milking period.<\/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<br \/>\n1 10<br \/>\n2 4<br \/>\n3 6<br \/>\n5 8<br \/>\n4 7<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\">\n<p><span class=\"sampledata\">4<\/span><\/p>\n<p>OUTPUT DETAILS:<\/p>\n<p>Here&#8217;s a graphical schedule for this output:<\/p>\n<p>Time 1 2 3 4 5 6 7 8 9 10<br \/>\nStall 1 c1&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br \/>\nStall 2 .. c2&gt;&gt;&gt;&gt;&gt;&gt; c4&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; .. ..<br \/>\nStall 3 .. .. c3&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; .. .. .. ..<br \/>\nStall 4 .. .. .. c5&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; .. .. ..<\/p>\n<p>Other outputs using the same number of stalls are possible.<\/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>\u4e0d\u59a8\u8bd5\u4e0b\u8fd9\u4e2a\u6570\u636e,\u5bf9\u4e8e\u6309\u7ed3\u675f\u70b9SORT,\u518dGREEDY\u7684\u505a\u6cd5 1 3 5 7 6 9 10 11 8 12 4 13 \u6b63\u786e\u7684\u8f93\u51fa\u5e94\u8be5\u662f3<\/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<p>\u778e\u641e\u4e86\u4e2a\u7ebf\u6bb5\u6811\uff0c\u636e\u8bf4\u795e\u7287\u7528\u7684\u65f6\u95f4\u6233<\/p>\n<pre class=\"lang:c++ decode:true \">#include&lt;cstdio&gt;\r\n#define M 1000010\r\ninline int read()\r\n{\r\n    int x=0;char ch=getchar();\r\n    while(ch&lt;'0'||ch&gt;'9') ch=getchar();\r\n    while(ch&gt;='0'&amp;&amp;ch&lt;='9'){x=x*10+ch-'0';ch=getchar();}\r\n    return x;\r\n}\r\ninline int max(int a,int b){return a&gt;b?a:b;}\r\nstruct ljn{int l,r,maxx,lazy;}tr[4*M];\r\nint n,x,y;\r\nvoid make(int l,int r,int p)\r\n{\r\n    tr[p].l=l,tr[p].r=r,tr[p].lazy=0;tr[p].maxx=0;\r\n    if(l==r) return;\r\n    int mid=(l+r)&gt;&gt;1;\r\n    make(l,mid,p&lt;&lt;1);\r\n    make(mid+1,r,p&lt;&lt;1|1);\r\n}\r\nvoid pd(int p)\r\n{\r\n    int lz=tr[p].lazy;\r\n    tr[p&lt;&lt;1].lazy+=lz;\r\n    tr[p&lt;&lt;1|1].lazy+=lz;\r\n    tr[p&lt;&lt;1].maxx+=lz;\r\n    tr[p&lt;&lt;1|1].maxx+=lz;\r\n    tr[p].lazy=0;\r\n}\r\nvoid xg(int l,int r,int c,int p)\r\n{\r\n    if(tr[p].l==l&amp;&amp;tr[p].r==r)\r\n    {\r\n        tr[p].lazy+=c;\r\n        tr[p].maxx+=c;\r\n        return;\r\n    }\r\n    pd(p);\r\n    int mid=(tr[p].l+tr[p].r)&gt;&gt;1;\r\n    if(mid&gt;=r) xg(l,r,c,p&lt;&lt;1);\r\n    else if(mid&lt;l) xg(l,r,c,p&lt;&lt;1|1);\r\n    else \r\n    {\r\n        xg(l,mid,c,p&lt;&lt;1);\r\n        xg(mid+1,r,c,p&lt;&lt;1|1);\r\n    }\r\n    tr[p].maxx=max(tr[p&lt;&lt;1].maxx,tr[p&lt;&lt;1|1].maxx);\r\n}\r\nint main()\r\n{\r\n    n=read();\r\n    make(1,1000000,1);\r\n    for(int i=0;i&lt;n;i++)\r\n    {\r\n        x=read();y=read();\r\n        xg(x,y,1,1);\r\n    }\r\n    printf(\"%d\\n\",tr[1].maxx);\r\n}<\/pre>\n<p>\u53e6\u9644\u7b2c\u4e8c\u79cd\u505a\u6cd5<\/p>\n<pre class=\"lang:c++ decode:true\">#include&lt;cstdio&gt;\r\n#define M 1000000\r\ninline int max(int x,int y){return x&gt;y?x:y;}\r\ninline int read()\r\n{\r\n    int x=0;char ch=getchar();\r\n    while(ch&lt;'0'||ch&gt;'9') ch=getchar();\r\n    while(ch&gt;='0'&amp;&amp;ch&lt;='9'){x=x*10+ch-'0';ch=getchar();}\r\n    return x;\r\n}\r\nint n,a,b,t[M+10],ans,wei;\r\nint main()\r\n{\r\n    n=read();\r\n    while(n--)\r\n    {\r\n        a=read();b=read();\r\n        t[a]++;\r\n        t[b+1]--;\r\n        wei=max(b,wei);\r\n    }\r\n    for(int i=1;i&lt;=wei;i++)\r\n    {\r\n        t[i]=t[i-1]+t[i];\r\n        ans=max(ans,t[i]);\r\n    }\r\n    printf(\"%d\\n\",ans);\r\n}<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/1014417\/201701\/1014417-20170117142350552-625891162.png\" alt=\"\" \/><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; 1651: [Usaco2006 Feb]Stall Reservations \u4e13\u7528\u725b\u68da Tim [&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":[10],"class_list":["post-340","post","type-post","status-publish","format-standard","hentry","category-bzoj","tag-10"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/340","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=340"}],"version-history":[{"count":2,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/340\/revisions"}],"predecessor-version":[{"id":342,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/340\/revisions\/342"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}