我的为什么是50分啊,错到哪里了?
查看原帖
我的为什么是50分啊,错到哪里了?
1729356
Bang1212楼主2025/8/1 11:01
#include<bits/stdc++.h>
#define ll long long
#define samplepassediscorrect for(;;)
#define ull unsigned long long
#define jiasu ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define lowbit(x) (x&(-x))
#define N 100050
using namespace std;
struct point{
	ll x,y;
}arr[N]; 
bool cmp(point &s1,point &s2){
	if(s1.x==s2.x) return s1.y>s2.y;
	return s1.x<s2.x;
}
ll n,b[N],k;
struct Fenwick_Tree{
	ll tree[N]={0};
	void update(ll x,ll d){
		while(x<=n){
			tree[x]+=d;
			x+=lowbit(x);
		}
	}
	ll sum(ll x){
		ll ans=0;
		while(x>0){
			ans+=tree[x];
			x-=lowbit(x);
		}
		return ans;
	}
}; 
struct temp{
	ll x,num;
}a[N];
bool cmp2(temp &s1,temp &s2){return s1.x<s2.x;}
bool check(ll mid){
	for(int i=1;i<=n;i++){
		a[i].num=i;
		a[i].x=arr[i].y-mid*arr[i].x;
	}
	sort(a+1,a+1+n,cmp2);
	b[a[1].num]=1;
	ll now=a[1].x,cnt=1;
	for(int i=2;i<=n;i++){
		if(a[i].x!=now){
			b[a[i].num]=++cnt;
			now=a[i].x;
		}
		else b[a[i].num]=cnt;
	}
	Fenwick_Tree r;
	ll sum=0;
	for(int i=1;i<=n;i++){
		r.update(b[i],1);
		sum+=r.sum(b[i]-1);
		if(sum>=k) return true;
	}	
	return false;
}
int main(){
jiasu;
cin>>n>>k;
for(int i=1;i<=n;i++)
	cin>>arr[i].x>>arr[i].y;
sort(arr+1,arr+1+n,cmp);
ll l=-1e9,r=1e9;
while(l+1<r){
	double mid=(l+r)/2;
	if(check(mid)) l=mid;
	else r=mid;
}
cout<<l;
	return 0;
} 
2025/8/1 11:01
加载中...