0pts玄关
查看原帖
0pts玄关
1046223
Star_Sky_楼主2024/9/20 13:23
#include <iostream>
#include <cstdio>

using namespace std;

int n, l, r, mid, cnt, ans;
int p1[100005], p2[100005], mp[100005], dp[100005]={1145140};

int main(){
	scanf("%d", &n);
	for(int i=1; i<=n; i++)scanf("%d", &p1[i]), mp[p1[i]]=i;
	for(int i=1; i<=n; i++)scanf("%d", &p2[i]), p2[i]=mp[p2[i]];
	
	for(int i=1; i<=n; i++){
		l=0, r=ans;
		while(l<=r){
			mid=(l+r)/2;
			
			if(dp[mid]>=p2[i]){
				cnt=mid;
				l=mid+1;
			}
			else r=mid-1;
		}
		
		ans=max(ans,cnt+1);
		dp[cnt+1]=p2[i];
	}
	
	printf("%d", ans);
	return 0;
}
2024/9/20 13:23
加载中...