90pts 求助!!!

P1439 【模板】最长公共子序列

bcbgszyzh @ 2024-04-08 16:27:46

#include<bits/stdc++.h>
using namespace std;
const int MAXN=1E6+5;
int n,a[MAXN],flag[MAXN],f[MAXN],l; 
int main(){
    scanf("%d",&n);
    for(int i=1,x;i<=n;++i){
        scanf("%d",&x);
        flag[x]=i;
    }
    for(int i=1,x;i<=n;++i){
        scanf("%d",&x);
        a[i]=flag[x];
    }
    for(int i=2;i<=n;++i){
        if(a[i]>f[l]){
            f[++l]=a[i];
        }else{
            int p=upper_bound(f+1,f+l+1,a[i])-f;
            f[p]=a[i];
        }
    }
    printf("%d",l);
    return 0;
}

by Nazq @ 2024-04-12 20:53:40

@bcbgszyzh 从 1 开始枚举


by bcbgszyzh @ 2024-04-12 21:37:13

@LaiShine


by Nazq @ 2024-04-12 21:44:27

不谢 @bcbgszyzh


|