LuoGu 1439 Lis

https://www.luogu.org/problemnew/show/P1439

Just look is the exposed Lcs Problem

But the range of Data is not allowed

But attention that this is the permutation

So you can choose a permutation as the standard

And then the problem become the Lis problem

The former is n*n

But the latter can be solved by time of n*logn

So this problem is solved

这道题以前看过

李煜东的书上好像有

要不就是刘汝佳的蓝书上

记不清了

Code of AC:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+100;
int A[N],B[N],C[N],D[N];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;++i) cin>>A[i];
    for(int i=1;i<=n;++i) cin>>C[i],D[C[i]]=i;
    for(int i=1;i<=n;++i) A[i]=D[A[i]];
    B[1]=A[1];
    int m=1;
    for(int i=2;i<=n;++i){  
        int l=0,r=m;
        while(l<r){
            int mid=(l+r+1)/2;
            if(B[mid]<=A[i])
                l=mid;
            else
                r=mid-1;
        }
        if(B[l+1]==0)
            B[l+1]=A[i];
        else
            B[l+1]=min(B[l+1],A[i]);
        m=max(l+1,m);
    }
    cout<<m<<endl;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值