{"id":141,"date":"2010-03-06T12:29:00","date_gmt":"2010-03-06T04:29:00","guid":{"rendered":"http:\/\/localhost\/?p=141"},"modified":"2010-03-06T12:29:00","modified_gmt":"2010-03-06T04:29:00","slug":"vijos_1549_median","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/wjmzbmr\/?p=141","title":{"rendered":"\u3010VIJOS 1549\u3011 \u4e2d\u4f4d\u6570"},"content":{"rendered":"<p> <a target=\"_blank\" href=\"http:\/\/www.vijos.cn\/Problem_Show.asp?id=1549\">www.vijos.cn\/Problem_Show.asp<\/a><br \/>\u4e5f\u662f<a href=\"http:\/\/61.187.179.132:8080\/JudgeOnline\/showproblem?problem_id=1303\" target=\"_blank\">[CQOI2009]\u4e2d\u4f4d\u6570\u56fe<\/a><br \/>\u989d\u3002\u3002\u8bbeb\u6240\u5728\u4f4d\u7f6e\u4e3ax\uff0c<br \/>\u8bbe\u4e00\u4e2a\u6570\u5217S\u4e2d\u5927\u4e8eb\u7684\u6570\u7684\u6570\u91cf-\u5c0f\u4e8eb\u7684\u6570\u7684\u6570\u91cfF(S)<br \/>\u90a3\u4e48\u8fd9\u4e2a\u5e8f\u5217\u7531x\u5de6\u8fb9\u7684\u4e00\u4e9b\u548c\u53f3\u8fb9\u7684\u4e00\u4e9b\u6784\u6210\uff0c\u4e14F(Left)+F(Right)=0\u3002\u3002<br \/>\u90a3\u4e48\u5c31\u5f88\u7b80\u5355\u4e86\u3002\u3002\u4ecex\u5f80\u53f3\u626b\u63cf\u4e00\u904d\uff0c\u8bb0\u5f55\u6bcf\u4e2aF(S)\u51fa\u73b0\u4e86\u51e0\u6b21\uff0c\u653e\u5728Count\u6570\u7ec4\u91cc<br \/>\u518d\u5f80\u5de6\u626b\u63cf\u4e00\u904d\uff0c\u82e5\u5f53\u524dF\u503c\u4e3anow,\u53ea\u8981\u628a\u7b54\u6848+\u4e0aCount[-now]\u5c31\u53ef\u4ee5\u4e86<br \/>0ms1A\u3002\u3002\u771f\u662f\u723d\u554a\u3002\u3002<br \/>Code\uff1a<br \/>#include&lt;cstdio&gt;<br \/>#include&lt;iostream&gt;<br \/>#include&lt;algorithm&gt;<br \/>#include&lt;string&gt;<br \/>#include&lt;vector&gt;<br \/>#include&lt;cstring&gt;<br \/>#define rep(i,n) for(int i=0;i&lt;n;i++)<br \/>#define pb push_back<br \/>using namespace std;<br \/>const int inf=~0U&gt;&gt;1;<br \/>const int maxn=1e5+10;<br \/>int main()<br \/>{<br \/>    \/\/freopen(&quot;in&quot;,&quot;r&quot;,stdin);<br \/>    int n,b;int A[maxn];<br \/>    int C[maxn*2]={0};<br \/>    cin&gt;&gt;n&gt;&gt;b;int x;<br \/>    rep(i,n) scanf(&quot;%d&quot;,A+i),x=(A[i]==b?i:x);<br \/>    int now=0;<br \/>    C[now+maxn]++;<br \/>    for(int i=x+1;i&lt;n;i++)<br \/>    {<br \/>        if(A[i]&gt;b) now++;<br \/>        else now&#8211;;<br \/>        C[now+maxn]++;<br \/>    }<br \/>    long long ans=0;<br \/>    now=0;ans+=C[now+maxn];<br \/>    for(int i=x-1;i&gt;=0;&#8211;i)<br \/>    {<br \/>        if(A[i]&gt;b) now++;<br \/>        else now&#8211;;<br \/>        ans+=C[maxn-now];<br \/>    }<br \/>    cout&lt;&lt;ans&lt;&lt;endl;<br \/>}<br \/>P.S\u6700\u8fd1\u5728\u505a\u4ee5\u524d\u6d59\u6c5f\u7701\u6570\u5b66\u7ade\u8d5b\u7684\u5377\u5b50\uff0c\u7a81\u7136\u7075\u673a\u4e00\u52a8\u60f3\u51fa\u4e86\u4e00\u9053\u7f16\u7a0b\u9898\uff0c\u5c31\u4ea4\u5230Vijos\u4e0a\u9762\u53bb\u4e86\u3002\u3002\u4e0d\u77e5\u9053\u80fd\u4e0d\u80fd\u901a\u8fc7\u56e7\u3002\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>www.vijos.cn\/Problem_Show.asp\u4e5f\u662f[CQOI2009]\u4e2d\u4f4d\u6570\u56fe\u989d\u3002\u3002\u8bbeb\u6240\u5728\u4f4d\u7f6e\u4e3ax\uff0c\u8bbe\u4e00\u4e2a\u6570\u5217S\u4e2d\u5927\u4e8eb\u7684\u6570\u7684\u6570\u91cf-\u5c0f\u4e8eb\u7684\u6570\u7684\u6570\u91cfF(S)\u90a3\u4e48\u8fd9\u4e2a\u5e8f\u5217\u7531x\u5de6\u8fb9\u7684\u4e00\u4e9b\u548c\u53f3\u8fb9\u7684\u4e00\u4e9b\u6784\u6210\uff0c\u4e14F(Left)+F(Right)=0\u3002\u3002\u90a3\u4e48\u5c31\u5f88\u7b80\u5355\u4e86\u3002\u3002\u4ecex\u5f80\u53f3\u626b\u63cf\u4e00\u904d\uff0c\u8bb0\u5f55\u6bcf\u4e2aF(S)\u51fa\u73b0\u4e86\u51e0\u6b21\uff0c\u653e\u5728Count\u6570\u7ec4\u91cc\u518d\u5f80\u5de6\u626b\u63cf\u4e00\u904d\uff0c\u82e5\u5f53\u524dF\u503c\u4e3anow,\u53ea\u8981\u628a\u7b54\u6848+\u4e0aCount[-now]\u5c31\u53ef\u4ee5\u4e860ms1A\u3002\u3002\u771f\u662f\u723d\u554a\u3002\u3002Code\uff1a#include&lt;cstdio&gt;#include&lt;iostream&gt;#include&lt;algorithm&gt;#include&lt;string&gt;#include&lt;vector&gt;#include&lt;cstring&gt;#define rep(i,n) for(int i=0;i&lt;n;i++)#define pb push_backusing namespace std;const int inf=~0U&gt;&gt;1;const int maxn=1e5+10;int main(){ \/\/freopen(&quot;in&quot;,&quot;r&quot;,stdin); int n,b;int A[maxn]; int C[maxn*2]={0}; cin&gt;&gt;n&gt;&gt;b;int x; rep(i,n) scanf(&quot;%d&quot;,A+i),x=(A[i]==b?i:x); int now=0; C[now+maxn]++; for(int i=x+1;i&lt;n;i++) { if(A[i]&gt;b) now++; else now&#8211;; C[now+maxn]++; } long long ans=0; now=0;ans+=C[now+maxn]; for(int i=x-1;i&gt;=0;&#8211;i) { if(A[i]&gt;b) now++; else now&#8211;; ans+=C[maxn-now]; } cout&lt;&lt;ans&lt;&lt;endl;}P.S\u6700\u8fd1\u5728\u505a\u4ee5\u524d\u6d59\u6c5f\u7701\u6570\u5b66\u7ade\u8d5b\u7684\u5377\u5b50\uff0c\u7a81\u7136\u7075\u673a\u4e00\u52a8\u60f3\u51fa\u4e86\u4e00\u9053\u7f16\u7a0b\u9898\uff0c\u5c31\u4ea4\u5230Vijos\u4e0a\u9762\u53bb\u4e86\u3002\u3002\u4e0d\u77e5\u9053\u80fd\u4e0d\u80fd\u901a\u8fc7\u56e7\u3002\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts\/141"}],"collection":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=141"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts\/141\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}