p1627 [CQOI2009]中位数
作者:互联网
分析
https://www.luogu.org/blog/user43145/solution-p1627
代码
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<cctype> #include<cmath> #include<cstdlib> #include<queue> #include<ctime> #include<vector> #include<set> #include<map> #include<stack> using namespace std; #define li long long const int N = 1e5; li a[2*N+10],b[2*N+10],Ans=1; int d[N+10]; int main(){ int n,m,i,j,k; scanf("%d%d",&n,&k); for(i=1;i<=n;i++){ scanf("%d",&d[i]); if(d[i]<k)d[i]=-1; else if(d[i]>k)d[i]=1; else d[i]=0,j=i; } m=0; for(i=j-1;i>0;i--){ m+=d[i]; a[m+N]++; } m=0; for(i=j+1;i<=n;i++){ m+=d[i]; b[m+N]++; } Ans+=a[N]+b[N]; for(i=0;i<=2*N;i++) Ans+=a[i]*b[2*N-i]; cout<<Ans; return 0; }
标签:10,int,中位数,long,li,CQOI2009,p1627,include 来源: https://www.cnblogs.com/yzxverygood/p/10354465.html