蒟蒻求助
查看原帖
蒟蒻求助
579266
Dr_MING楼主2022/9/27 21:14

小样例都过了,样例三就是过不去了。。。

#include<bits/stdc++.h>
#define maxm 100010
using namespace std;

int n,m1,m2,a1,a2,b1,b2,ans,cnt1,cnt2;
int head1[maxm],head2[maxm],tot1[maxm],tot2[maxm];
struct node
{
	int x,y;
	bool operator < (const node & a) const
	{
		return x>a.x;
	}
}k;
priority_queue <node> q;
struct edge1{
	int x1,y1;
}dep1[maxm];
struct edge2{
	int x2,y2;
}dep2[maxm];

bool cmp1(edge1 a,edge1 b){
	return a.x1<b.x1;
}
bool cmp2(edge2 a,edge2 b){
	return a.x2<b.x2;
}

void init(){
	scanf("%d%d%d",&n,&m1,&m2);
	for(int i=1;i<=m1;i++){
		scanf("%d%d",&a1,&b1);
		dep1[i].x1=a1;
		dep1[i].y1=b1;
	}
	for(int i=1;i<=m2;i++){
		scanf("%d%d",&a2,&b2);
		dep2[i].x2=a2;
		dep2[i].y2=b2;
	}
	sort(dep1+1,dep1+m1+1,cmp1);
	sort(dep2+1,dep2+m2+1,cmp2);
	
	for(int i=1;i<=m1;i++){
		int u1=dep1[i].x1;
		bool vis1=false;
		if(i==1){
			head1[++cnt1]=1;
			tot1[cnt1]++;
			k.x=dep1[1].y1,k.y=cnt1;
			q.push(k);
			vis1=true;
			continue;
		}
		node m=q.top();
		if(u1>m.x){
			q.pop();
			head1[m.y]=i;
			vis1=true;
			tot1[m.y]++;
			k.x=dep1[i].y1,k.y=m.y;
			q.push(k);
			continue;
		}
		if(vis1==false){
			head1[++cnt1]=i;
			tot1[cnt1]++;
			k.x=dep1[i].y1,k.y=cnt1;
			q.push(k);
		}
	}
	while(!q.empty())	q.pop();
	for(int i=1;i<=m2;i++){
		int u1=dep2[i].x2;
		bool vis2=false;
		if(i==1){
			head2[++cnt2]=1;
			tot2[cnt2]++;
			k.x=dep2[1].y2,k.y=cnt2;
			q.push(k);
			vis2=true;
			continue;
		}
		node m=q.top();
		if(u1>m.x){
			q.pop();
			head2[m.y]=i;
			vis2=true;
			tot2[m.y]++;
			k.x=dep2[i].y2,k.y=m.y;
			q.push(k);
			continue;
		}
		if(vis2==false){
			head2[++cnt2]=i;
			tot2[cnt2]++;
			k.x=dep2[i].y2,k.y=cnt2;
			q.push(k);			
		}
	}
}

void chuli(){
	for(int j=1;j<=n;j++)
		tot1[j]=tot1[j-1]+tot1[j];
	for(int j=1;j<=n;j++)
		tot2[j]=tot2[j-1]+tot2[j];
	for(int mid=0;mid<=n;mid++)
		ans=max(ans,tot1[n-mid]+tot2[mid]);
}

int main(){
	init();
	chuli();
	printf("%d\n",ans);
	for(int i=1;i<=n;i++)
		cout<<tot1[i]<<" ";
	cout<<endl;
	for(int i=1;i<=n;i++)
		cout<<tot2[i]<<" ";
	return 0;
}
2022/9/27 21:14
加载中...