/ Randle /

记录详情

Wrong Answer


  
# 状态 耗时 内存占用
#1 Wrong Answer 7ms 3.57 MiB
#2 Accepted 3ms 3.699 MiB
#3 Accepted 3ms 3.574 MiB
#4 Wrong Answer 121ms 5.484 MiB
#5 Wrong Answer 47ms 4.203 MiB
#6 Accepted 88ms 4.438 MiB
#7 Accepted 82ms 4.449 MiB
#8 Accepted 76ms 4.195 MiB
#9 Accepted 114ms 5.195 MiB
#10 Accepted 74ms 5.309 MiB

代码

#include <bits/stdc++.h>
using namespace std;
int a[100001],b[100001];//原始数据 
double s[100001];//前序和 
struct node
{
	int p;
	double v;
	inline bool operator < (node x)
	{
		return v<x.v;
	}
}c[100001];//HASH
int HASH[100001];
int d[400001];//没错我就是树状数组!! 
inline int read()
{
	char ch=getchar();
	int x=0;
	while(!isdigit(ch))
		ch=getchar();
	while(isdigit(ch))
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x;
}
int n,k;

inline int sum(int x)
{
	int ans=0;
	while(x)
	{
		ans+=d[x];
		x-=(x&-x); 
	}
	return ans;
}
inline void in(int x)
{
	while(x<=n)
	{
		d[x]++;
		x+=(x&-x);
	}
}
bool judge(double x)
{
	memset(d,0,sizeof(d));
	int i,ans=0;
	for(i=1;i<=n;i++)
	{
		s[i]=s[i-1]+(double)a[i]-(double)b[i]*x;
		c[i].p=i,c[i].v=s[i];
	}
	sort(c+1,c+n+1);//HASH,将数转化为整数; 
	for(i=1;i<=n;i++)
	{
		HASH[c[i].p]=i;
		if(c[i].v==c[i-1].v&&HASH[c[i-1].p]!=0)
			HASH[c[i].p]=HASH[c[i-1].p];
	}
	for(i=1;i<=n;i++)//树状数组闪亮登场!!!! 
	{
		ans+=sum(HASH[i]);
		in(HASH[i]+1);
		if(ans>k)return true; 
	}
	return false;
}
int main()
{
	int i;
	double l=0,r=0,mid;
	n=read(),k=read();
	for(i=1;i<=n;i++)
		a[i]=read();
	for(i=1;i<=n;i++)
	{
		b[i]=read();
		r=max(r,(double)a[i]/b[i]);
	}
	while(l<r&&r-l>0.003)
	{
		mid=(l+r)/2;
		if(judge(mid)) l=mid;
		else r=mid;
	}
	printf("%.2lf",l);
}

信息

递交者
类型
递交
题目
梁山伯与祝英台(原创)
题目数据
下载
语言
C++
递交时间
2017-10-26 20:26:43
评测时间
2017-10-26 20:26:43
评测机
分数
70
总耗时
620ms
峰值内存
5.484 MiB