这个官方数据也太逊了吧
查看原帖
这个官方数据也太逊了吧
92401
Gu_Ren楼主2021/11/1 17:51

微调三分+o(nlogn)的check都过了

#include<bits/stdc++.h>
#define fo(i,l,r) for (int i=l; i<=r; i++)
#define fr(i,l,r) for (int i=l; i<r; i++)
#define dw(i,r,l) for (int i=r; i>=l; i--)
using namespace std;
const int N=100006;
struct wc{
	int a,b,c;
}x[N];
priority_queue<int,vector<int>,greater<int> >p;
priority_queue<int,vector<int>,greater<int> >q;
int n,m1,m2,m,ans;
bool cmp(wc x,wc y){ return x.a<y.a; } 
int check(int xx){ 
	while (!p.empty()) p.pop();
	while (!q.empty()) q.pop();
	int s=0,k0=0,k1=0;
	fo(j,1,m){
		if (x[j].c==0){
			while (!p.empty()&&p.top()<x[j].a) p.pop(),k0--;
			if (k0<xx) p.push(x[j].b),k0++,s++;
		}
		if (x[j].c==1){
			while (!q.empty()&&q.top()<x[j].a) q.pop(),k1--;
			if (k1<n-xx) q.push(x[j].b),k1++,s++;
		}
	}
	ans=max(ans,s);
	return s;
}
int main(){
// 	freopen("airport.in","r",stdin);
// 	freopen("airport.out","w",stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	cin>>n>>m1>>m2;
	m=m1+m2;
	fo(i,1,m1){
		cin>>x[i].a>>x[i].b;
		x[i].c=0;
	}
	fo(i,1,m2){
		cin>>x[i+m1].a>>x[i+m1].b;
		x[i+m1].c=1;
	}
	sort(x+1,x+1+m,cmp);
	int l=0,r=n;
	check(l),check(r);
	while (r-l>7){
		int d1=l+(r-l)/6.5,d2=r-(r-l)/6.5;
		if (check(d1)<check(d2)) l=d1;
		else r=d2;
	}
	fo(i,l,r) check(i);
	cout<<ans;
	return 0;
}
2021/11/1 17:51
加载中...