{"id":626,"date":"2017-05-25T15:38:00","date_gmt":"2017-05-25T07:38:00","guid":{"rendered":"http:\/\/kylelv.com\/?p=626"},"modified":"2020-03-04T14:39:26","modified_gmt":"2020-03-04T06:39:26","slug":"bzoj-4397-usaco2015-decbreed-counting-%e5%89%8d%e7%bc%80%e5%92%8c","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=626","title":{"rendered":"bzoj 4397: [Usaco2015 dec]Breed Counting &#8212; \u524d\u7f00\u548c"},"content":{"rendered":"\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-69fdef44e20ed\" 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-69fdef44e20ed\"  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=626\/#4397_Usaco2015_decBreed_Counting\" title=\"4397: [Usaco2015 dec]Breed Counting\">4397: [Usaco2015 dec]Breed Counting<\/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=626\/#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=626\/#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=626\/#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=626\/#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=626\/#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=626\/#HINT\" title=\"HINT\">HINT<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"has-text-align-center wp-block-heading\"><span class=\"ez-toc-section\" id=\"4397_Usaco2015_decBreed_Counting\"><\/span>4397: [Usaco2015 dec]Breed Counting<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"has-text-align-center\">Time Limit:&nbsp;10 Sec&nbsp;&nbsp;Memory Limit:&nbsp;128 MB<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Description\"><\/span>Description<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Farmer John&#8217;s N cows, conveniently numbered 1\u2026N, are all standing in a row (they seem to do so often that it now takes very little prompting from Farmer John to line them up). Each cow has a breed ID: 1 for Holsteins, 2 for Guernseys, and 3 for Jerseys. Farmer John would like your help counting the number of cows of each breed that lie within certain intervals of the ordering.<\/p>\n\n\n\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3aN\u7684\u5e8f\u5217\uff0c\u6bcf\u4e2a\u4f4d\u7f6e\u4e0a\u7684\u6570\u53ea\u53ef\u80fd\u662f1\uff0c2\uff0c3\u4e2d\u7684\u4e00\u79cd\u3002<\/p>\n\n\n\n<p>\u6709Q\u6b21\u8be2\u95ee\uff0c\u6bcf\u6b21\u7ed9\u5b9a\u4e24\u4e2a\u6570a,b\uff0c\u8bf7\u5206\u522b\u8f93\u51fa\u533a\u95f4[a,b]\u91cc\u6570\u5b571\uff0c2\uff0c3\u7684\u4e2a\u6570\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Input\"><\/span>Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The first line of input contains NN and QQ (1\u2264N\u2264100,000 1\u2264Q\u2264100,000).<br>The next NN lines contain an integer that is either 1, 2, or 3, giving the breed ID of a single cow in the ordering.<br>The next QQ lines describe a query in the form of two integers a,b (a\u2264b).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Output\"><\/span>Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>For each of the QQ queries (a,b), print a line containing three numbers: the number of cows numbered a\u2026b that are Holsteins (breed 1), Guernseys (breed 2), and Jerseys (breed 3).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Sample_Input\"><\/span>Sample Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>6 3<br>2<br>1<br>1<br>3<br>2<br>1<br>1 6<br>3 3<br>2 4<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Sample_Output\"><\/span>Sample Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>3 2 1<br>1 0 0<br>2 0 1<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"HINT\"><\/span>HINT<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;map>\n#include&lt;cmath>\n#include&lt;queue>\n#include&lt;cstdio>\n#include&lt;cstring>\n#include&lt;iostream>\n#include&lt;algorithm>\nusing namespace std;\n#define ll long long\n#define N 100010\nchar xB&#91;1&lt;&lt;15],*xS=xB,*xTT=xB;\n#define getc() (xS==xTT&amp;&amp;(xTT=(xS=xB)+fread(xB,1,1&lt;&lt;15,stdin),xS==xTT)?0:*xS++)\n#define isd(c) (c>='0'&amp;&amp;c&lt;='9')\ninline int read(){\n    char xchh;\n    int xaa;\n    while(xchh=getc(),!isd(xchh));(xaa=xchh-'0');\n    while(xchh=getc(),isd(xchh))xaa=xaa*10+xchh-'0';return xaa;\n}\nint n,q,x,y,s&#91;N]&#91;4];\nint main()\n{\n    n=read();q=read();\n    for(int i=1;i&lt;=n;i++)\n    {\n        x=read();\n        s&#91;i]&#91;1]=s&#91;i-1]&#91;1];\n        s&#91;i]&#91;2]=s&#91;i-1]&#91;2];\n        s&#91;i]&#91;3]=s&#91;i-1]&#91;3];\n        s&#91;i]&#91;x]++;\n    }\n    while(q--)\n    {\n        x=read();y=read();\n        printf(\"%d %d %d\\n\",s&#91;y]&#91;1]-s&#91;x-1]&#91;1],s&#91;y]&#91;2]-s&#91;x-1]&#91;2],s&#91;y]&#91;3]-s&#91;x-1]&#91;3]);\n    }\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>4397: [Usaco2015 dec]Breed Counting Time Limit:&nbsp;10 [&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,66],"tags":[25],"class_list":["post-626","post","type-post","status-publish","format-standard","hentry","category-bzoj","category-usaco","tag-25"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/626","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=626"}],"version-history":[{"count":1,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/626\/revisions"}],"predecessor-version":[{"id":627,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/626\/revisions\/627"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=626"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=626"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=626"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}