Match gene matching solution to a problem (From luoguBlog)

N <= 20000! LCS place of N2 to explode.

To optimize the examination room your mother watched on the line TLE60 really fragrant hey hey hey

However, this is obviously a board just like me experience short-sighted of konjac do not know it

Correct answer:

A gangster's blog

Into binary complexity nlogn after lis.

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,s1[100010],s2[100010],pos[20010][8],num[20010]={0};
int tot=0,res[500010];
int ans=1,f[500010];
int main()
{
    //freopen("lis.out","w",stdout);
    cin>>n;
    n*=5;
    for(int i=1;i<=n;i++)scanf("%d",&s1[i]);
    for(int i=1;i<=n;i++)scanf("%d",&s2[i]),pos[s2[i]][++num[s2[i]]]=i;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=5;j++)res[++tot]=pos[s1[i]][5-j+1];
    /*cout<<endl;
    for(int i=1;i<=tot;i++)cout<<res[i]<<' ';
    cout<<endl;*/
    f[1]=res[1];
    for(int i=2;i<=tot;i++)
    {
        if(res[i]>f[ans])
        {
            ans++;
            f[ans]=res[i];
        }
        else
        {
            int loc=lower_bound(f+1,f+ans+1,res[i])-f;
            f[loc]=res[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Guess you like

Origin www.cnblogs.com/Rorschach-XR/p/10969117.html