{"id":37,"date":"2016-05-05T20:18:09","date_gmt":"2016-05-05T12:18:09","guid":{"rendered":"http:\/\/tyswly.com\/?p=37"},"modified":"2016-05-05T20:18:09","modified_gmt":"2016-05-05T12:18:09","slug":"%e6%b4%9b%e8%b0%b7p1908%e9%80%86%e5%ba%8f%e5%af%b9","status":"publish","type":"post","link":"https:\/\/tys.fun\/?p=37","title":{"rendered":"[\u6d1b\u8c37P1908]\u9006\u5e8f\u5bf9"},"content":{"rendered":"<p>\u9898\u76ee\u89c1<a href=\"http:\/\/www.luogu.org\/problem\/show?pid=1908\">\u6d1b\u8c37<\/a><br \/>\n\u5206\u6790\uff1a\u9996\u5148\uff0c\u8fd9\u9053\u9898\u9700\u8981\u8fdb\u884c\u4e00\u6b21\u6392\u5e8f\uff0c\u9898\u76ee\u4e2d\u6ca1\u6709\u7ed9\u51fa\u6570\u636e\u8303\u56f4\uff0c\u4f46\u662f\u5b9e\u6d4b\u9700\u8981\u4f7f\u7528\u79bb\u6563\u5316\u3002\u3002\/\/\u8bdd\u8bf4\u79bb\u6563\u5316\u771f\u7684\u597d\u70e6\u4eba\u554a\u3002\u3002\uff08\u96fe\u3002\u3002<br \/>\n\u5176\u6b21\uff0c\u6211\u8ba4\u4e3a\u8fd9\u9053\u9898\u662f\u53ef\u4ee5\u7528\u7ebf\u6bb5\u6811\u505a\u7684\uff01\uff01\uff01\/\/\u867d\u7136\u6211\u6ca1\u5199\u51fa\u6765\uff0c\u4ee3\u7801\u592a\u5197\u957f\u4e86\uff08\u96fe\u3002\u3002<br \/>\n\u603b\u4e4b\uff0c\u8fd8\u662f\u819c\u4e86\u4e00\u53d1\u4e8c\u53c9\u7d22\u5f15\u6811\uff0c<del>\u53d1\u73b0\u8fd9\u79cd\u795e\u5947\u7684\u7b97\u6cd5\u771f\u7684\u662f\u592a\u795e\u5947\u4e86\uff01<\/del> \u6211\u771f\u7684\u5f88\u4f69\u670d\u8fd9\u4e2a\u7b97\u6cd5\u7684\u53d1\u660e\u8005\u7684\u667a\u5546\uff0c\u65b9\u6cd5\u5b9e\u5728\u592a\u5de7\u5999\u4e86\u3002<a href=\"https:\/\/www.cs.auckland.ac.nz\/~peter-f\/\">@Peter M. Fenwick<\/a><br \/>\n\u7b80\u5355\u4ecb\u7ecd\u4e00\u4e0b\u8fd9\u4e2a\u7b97\u6cd5\uff1a\u5229\u7528\u4e8c\u53c9\u6811<del>\uff08\u5e9f\u8bdd\uff0c\u540d\u5b57\u90fd\u662f\u4e8c\u53c9\u7d22\u5f15\u6811\u3002\u3002\uff09<\/del>\u8fdb\u884c\u6570\u636e\u7684\u5b58\u50a8\u53ca\u7ef4\u62a4\uff0c\u5de7\u5999\u5730\u5229\u7528\u8865\u7801\u8868\u793a\u6cd5\u548c\u4e8c\u8fdb\u5236\u6570\u636e\u7684\u7279\u70b9\uff0c\u8fdb\u884c\u8282\u70b9\u7684\u5b9a\u4f4d\uff0c\u6210\u529f\u5730\u505a\u5230\u4e86\u628a\u65f6\u95f4\u590d\u6742\u5ea6\u538b\u7f29\u5230O(log n)\uff0c\u7ee7\u7eed\u819c\u62dc\u53d1\u660e\u8005\u3002\u3002<br \/>\n\u4ee5\u4e0b\u662f\u4ee3\u7801\uff0c\u4e3a\u4e86\u8bad\u7ec3\u8bfb\u8005\u7684\u4ee3\u7801\u9605\u8bfb\u80fd\u529b\uff0c\u672c\u4ee3\u7801\u4e0d\u6dfb\u52a0\u6ce8\u91ca<del>\uff08\u867d\u7136\u662f\u6211\u61d2\uff09<\/del><\/p>\n<pre class=\"lang:c++ decode:true \">#include &lt;iostream&gt;\n#include &lt;cstdio&gt;\n#include &lt;vector&gt;\n#include &lt;algorithm&gt;\nusing namespace std;\nstruct node{\n\tint c, l;\n};\nnode da[40005];\nint n, cnt;\nint has[40005], c[40005];\nint get_num();\nbool cmp(node a, node b)\n{\n\treturn a.c&lt;b.c;\n}\ninline int lowbit(int x)\n{\n\treturn x&amp;(-x);\n}\ninline int add(int x, int d)\n{\n\twhile(x&lt;=n)\n\t{\n\t\tc[x]+=d;\n\t\tx+=lowbit(x);\n\t}\n}\ninline int sum(int x)\n{\n\tint tmp=0;\n\twhile(x&gt;0)\n\t{\n\t\ttmp+=c[x];\n\t\tx-=lowbit(x);\n\t}\n\treturn tmp;\n}\nint main()\n{\n\tn=get_num();\n\tfor(int i=1;i&lt;=n;i++)\n\t{\n\t\tda[i].c=get_num();\n\t\tda[i].l=i;\n\t}\n\tsort(da+1,da+n+1,cmp);\n\tfor(int i=1;i&lt;=n;i++)\n\t{\n\t\thas[da[i].l]=i;\n\t}\n\tlong long ans=0;\n\tfor(int i=n;i&gt;=1;i--)\n\t{\n\t\tadd(has[i],1);\n\t\tans+=sum(has[i]-1);\n\t}\n\tcout&lt;&lt;ans&lt;&lt;\"\\n\";\n\treturn 0;\n}\ninline int get_num()\n{\n\tint ans=0;\n\tchar tmp;\n\ttmp=getchar();\n\twhile(tmp&gt;'9'||tmp&lt;'0')\ttmp=getchar();\n\twhile(tmp&lt;='9'&amp;&amp;tmp&gt;='0')\n\t{\n\t\tans=ans*10+tmp-48;\n\t\ttmp=getchar();\n\t}\n\treturn ans;\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee\u89c1\u6d1b\u8c37 \u5206\u6790\uff1a\u9996\u5148\uff0c\u8fd9\u9053\u9898\u9700\u8981\u8fdb\u884c\u4e00\u6b21\u6392\u5e8f\uff0c\u9898\u76ee\u4e2d\u6ca1\u6709\u7ed9\u51fa\u6570\u636e\u8303\u56f4\uff0c\u4f46\u662f\u5b9e\u6d4b\u9700\u8981\u4f7f\u7528\u79bb\u6563\u5316\u3002\u3002\/\/\u8bdd\u8bf4\u79bb\u6563 &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-37","post","type-post","status-publish","format-standard","hentry","category-report"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tys.fun\/index.php?rest_route=\/wp\/v2\/posts\/37","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tys.fun\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tys.fun\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tys.fun\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tys.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=37"}],"version-history":[{"count":0,"href":"https:\/\/tys.fun\/index.php?rest_route=\/wp\/v2\/posts\/37\/revisions"}],"wp:attachment":[{"href":"https:\/\/tys.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=37"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tys.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=37"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tys.fun\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=37"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}