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;
}