30分求助!!!
查看原帖
30分求助!!!
753880
awawawawa楼主2024/8/3 19:19

不知道有啥问题,求调

#include<bits/stdc++.h>
using namespace std;
struct Node {
	int l,r;
	bool operator<(const Node &b) {
		return l<b.l;
	}
};
const int maxn=1e5+10;
int n,dp[maxn];
Node a[maxn];
int main() {
	cin>>n;
	for(int i=1; i<=n; i++)
		cin>>a[i].l;
	for(int i=1; i<=n; i++)
		cin>>a[i].r;
	sort(a+1,a+1+n);
	int len=1;
	dp[len]=a[1].r;
	for(int i=2; i<=n; i++) {
		if(dp[len]<a[i].r)
			dp[++len]=a[i].r;
		else {
			int pos=lower_bound(dp+1,dp+1+len,a[i].r)-dp;
			dp[pos]=a[i].r;
		}
	}
	cout<<len<<endl;
	return 0;
}
2024/8/3 19:19
加载中...