61pts,样例挂了,求助
查看原帖
61pts,样例挂了,求助
285617
黑影洞人楼主2023/8/29 18:07
#include<cstdio>
#include<algorithm>
#define N 214514
using namespace std;
int n,m,tot;
struct ohqlovehxr{
	int x,y,typ,id;
	bool operator<(const ohqlovehxr &a)const{return x<a.x;}
}q[N],tmp[N];
int dp[N],cst[N];
void cdq(int l,int r){
	if(l==r)return;
	int mid=(l+r)/2;
	cdq(l,mid);cdq(mid+1,r);
	int i=l,k=l,j=mid+1,res=0;
	while(i<=mid&&j<=r){
		if(q[i].y<=q[j].y){
			if(q[i].typ==2)res=max(dp[q[i].id],res);
			tmp[k++]=q[i++];
		}else{
			if(q[j].typ==1)dp[q[j].id]=max(dp[q[j].id],res+cst[q[j].id]);
			tmp[k++]=q[j++];
		}
	}
	while(i<=mid){
		if(q[i].typ==2)res=max(dp[q[i].id],res);
		tmp[k++]=q[i++];
	}
	while(j<=r){
		if(q[j].typ==1)dp[q[j].id]=max(dp[q[j].id],res+cst[q[j].id]);
		tmp[k++]=q[j++];
	}
	for(int i=l;i<=r;i++)q[i]=tmp[i];
}
signed main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		cst[i]=c+d-a-b;
		q[++tot]={a,b,1,i};
		q[++tot]={c,d,2,i};
	}
	sort(q+1,q+tot+1);
	cdq(1,tot);
	int ans=0;
	for(int i=1;i<=m;i++)ans=max(dp[i],ans);
	printf("%d",2*n-ans);
	return 0;
}



2023/8/29 18:07
加载中...