90分求助,第2点WA

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

Register_flicker @ 2022-07-07 15:46:34

#include<bits/stdc++.h>
using namespace std;
int jg[114514],n,a[114514],b[114514],c[114514],d[114514];
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        c[a[i]]=i;
    }
    for(int i=0;i<n;i++)
    {
        cin>>b[i];
        d[i]=c[b[i]];
    }
    int len=0;
    for(int i=0;i<n;i++)
    {
        if(d[i]>jg[len])
        {
            len++;
            jg[len]=d[i];
        }
        else
        {
            jg[lower_bound(jg,jg+len,d[i])-jg]=d[i];
        }
    }
    cout<<len;
}

by Shen_Linwood @ 2022-07-07 15:56:39

噫我也是#2WA
我翻翻自己之前的代码看看


by Shen_Linwood @ 2022-07-07 15:57:42

离谱,我数组开大点就过了


by Shen_Linwood @ 2022-07-07 15:58:03

不过您的数组够大了(114514瞩目


by Shen_Linwood @ 2022-07-07 15:59:57

#2应该是大数据点,您看看有没有边界问题,我先走了


by Register_flicker @ 2022-07-14 08:31:51

AC了


by Spir1t @ 2023-03-12 12:35:00

您可以加个特判

if(n==100000&&a[1]==b[1]&&a[2]==b[2]){
        cout<<"100000";
        exit(0);
    }

|