有没有好心人能帮我看一下(92)
查看原帖
有没有好心人能帮我看一下(92)
523525
徐天乾楼主2021/8/3 20:14

评测:https://www.luogu.com.cn/record/54892774

#include<bits/stdc++.h>
#define M 500500
using namespace std;
struct o{int a,b;}c[M];
bool cmp(o a,o b){return a.a<b.a;}
int P,Q,i,n,m,k,t,w,mid,W,a[M],b[500000],d[M],e[M],E[M],f[M];
void po(int q){
	int t;
	P++;t=P;e[P]=c[q].b;E[P]=q;
	while (t>1&&e[t/2]<e[t])
		swap(e[t/2],e[t]),swap(E[t/2],E[t]),t=t/2;
}
int pu(){
	int t,O,son;
	if (!P) return -1;
	O=E[1];t=1;
	e[1]=e[P];E[1]=E[P];P--;
	while (t*2<=P){
		son=t*2;
		if (son+1<=P&&e[t*2]<e[t*2+1]) son++;
		if (e[son]<=e[t]) return O;
		swap(e[son],e[t]);swap(E[son],E[t]);
		t=son;
	}
	return O;
}
bool check(int mid){
	int t,i,j,w,oo;
	t=1;P=Q=0;
	for (i=1;i<=k;i++) f[i]=0;
	for (i=1;i<=n;i++){
		while (t<=k&&c[t].a<a[i])
			po(t),t++;
		for (j=1;j<=mid;j++){
			oo=pu();
			if (oo==-1) break;
			f[oo]=1;
		}
	}
	t=m;w=mid;
	for (i=1;i<=k;i++)
		if (f[i]==0)
			d[++Q]=c[i].b;
	sort(d+1,d+1+Q);
	for (i=Q;i>0;i--){
		if (w==0) w=mid,t--;
		while (t>0&&b[t]<=d[i]) t--,w=mid;
		if (t>0) w--;
		else return false;
		}
	return true;
}
int main(){
	scanf("%d %d %d",&n,&m,&k);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	for (i=1;i<=m;i++) scanf("%d",&b[i]);
	sort(a+1,a+1+n);sort(b+1,b+1+m);
	for (i=1;i<=k;i++) scanf("%d %d",&c[i].a,&c[i].b);
	sort(c+1,c+1+k,cmp);
	t=1;w=200000;W=-1;
	while (t<=w){
		mid=(t+w)>>1;
		if (check(mid))
			W=mid,w=mid-1;
		else t=mid+1;
	}
	printf("%d\n",W);
}
2021/8/3 20:14
加载中...