标签:
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 using namespace std; 7 typedef long long int64; 8 const double eps=1e-5; 9 const int maxn=100005; 10 int n,a[maxn],sum[maxn],pos[maxn]; 11 double l,r,mid,ans,b[maxn],s[maxn],list[maxn]; 12 int64 k; 13 int lowbit(int x){return x&(-x);} 14 void insert(int x){for (int i=x;i<=n+1;i+=lowbit(i)) sum[i]++;} 15 int64 query(int x){ 16 int64 temp=0; 17 for (int i=x;i;i-=lowbit(i)) temp+=sum[i]; 18 return temp; 19 } 20 bool judge(double num){ 21 memset(sum,0,sizeof(sum)); b[0]=0; 22 for (int i=1;i<=n;i++) b[i]=a[i]-num; 23 for (int i=1;i<=n;i++) s[i]=s[i-1]+b[i],list[i]=s[i]; 24 list[n+1]=0; sort(list+1,list+n+2); 25 for (int i=1;i<=n;i++) pos[i]=lower_bound(list+1,list+n+2,s[i])-list; 26 pos[0]=lower_bound(list+1,list+n+2,0)-list; 27 int64 tot=0; 28 insert(pos[0]); 29 for (int i=1;i<=n;i++) tot+=query(pos[i]),insert(pos[i]); 30 return tot>=k; 31 } 32 int main(){ 33 scanf("%d%lld",&n,&k); 34 for (int i=1;i<=n;i++) scanf("%d",&a[i]); 35 l=1.0,r=100000.0; 36 while (l+eps<r){ 37 mid=(l+r)/2.0; 38 if (judge(mid)) l=mid; 39 else r=mid; 40 } 41 printf("%.4lf\n",l); 42 return 0; 43 }
题目大意:
LYK有一个长度为n的序列a。
标签:
原文地址:http://www.cnblogs.com/OYzx/p/5801317.html