跳到正文

个人记录

P16094

QWQ_3090nehciyuh约 2 分钟
原文
文章信息与版本

文章信息

收录
2026年7月16日
更新
2026年7月24日
篇幅
约 2 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
int n,A,B,dp[5006][5006];
set<int>st[5006];
vector<pair<int,int>>ud;
int main(){
	scanf("%d%d%d",&n,&A,&B);
	for (int i=0;i<=5000;i++) for (int j=0;j<=5000;j++) dp[i][j]=-1e9;
	dp[0][0]=0;
	st[0].insert(0);
	for (int i=0;i<=5000;i++) st[i].insert(6000);
	int ans=0;
	for (int i=1,al,ar,bl,br;i<=n;i++){
		scanf("%d%d%d%d",&al,&ar,&bl,&br);
		ar=min(ar-A,5000);
		br=min(br-B,5000);
		al=max(al-A,0);
		bl=max(bl-B,0);
		for (int a=al;a<=ar;a++){
			for (auto x=st[a].lower_bound(bl);;x++){
				int b=*x;
				if (b>br) break;
				ud.push_back({a,b});
				ans=max(ans,dp[a][b]+1);
			}
		}
		for (auto [a,b]:ud) st[a].erase(b);
		for (auto [a,b]:ud){
			if (dp[a+1][b]<dp[a][b]+1){
				dp[a+1][b]=dp[a][b]+1;
				st[a+1].insert(b);
			}
			if (dp[a][b+1]<dp[a][b]+1){
				dp[a][b+1]=dp[a][b]+1;
				st[a].insert(b+1);
			}
		}
		ud.clear();
	}
	printf("%d\n",ans);
	return 0;
}
原文