P1439 两个排列的最长公共子序列

点击查看代码
#include<bits/stdc++.h>
using namespace std;

const int N=1e5+10;
int n;
int pos[N];
int q[N],len;

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);

	cin>>n;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        pos[x]=i;
    }

    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        int p=pos[x];
        if(len==0||p>q[len]){
            q[++len]=p;
        }else{
            *lower_bound(q+1,q+len+1,p)=p;
        }
    }

    cout<<len<<"\n";

    return 0;
    
    
}
posted @ 2026-03-10 11:20  AnoSky  阅读(4)  评论(0)    收藏  举报