#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(2)
#define endl '\n'
const int N=2e6+10;
typedef long long ll;
ll ans=0,n1,m1;
ll s1=0,s2=0,s3=0,s4=0,max1=0,max2=0,w,min1=100000000,sum=0,n,m,i,j,k,v,l,r;
inline int read() {
bool sym=0;
int res=0;
char ch=getchar();
while(!isdigit(ch))sym |=(ch =='-'),ch=getchar();
while(isdigit(ch)) res =(res<<3)+(res<<1)+(ch^48),ch=getchar();
return sym ? -res : res;
}
void print(int x) {
if(!x)return;
print(x/10);
putchar(x%10+'0');
}
int isPrime(int n) {
float n_sqrt;
if(n==1) return 0;
if(n==2 || n==3) return 1;
if(n%6!=1 && n%6!=5) return 0;
n_sqrt=floor(sqrt((float)n));
for(int i=5; i<=n_sqrt; i+=6) {
if(n%(i)==0 | n%(i+2)==0) return 0;
}
return 1;
}
ll a[100086], b[100008];
ll t[100008];
ll low[100006] ;
int main() {
n = read();
ans=0;
for (ll i = 1; i <= n; i++) {
a[i] = read(), t[a[i]] = i;
}
for (ll i = 1; i <= n; i++) {
b[i] = read(), b[i] = t[b[i]];
}
for (ll i = 1; i <= n; i++) {
ll pos = lower_bound(low + 1, low + ans + 1, b[i]) - low;
low[pos] = b[i], ans = max(ans, pos);
}
cout << ans << endl;
return 0;
}
//mio lover
目的:在 b[]
中找到一个最长的子序列使得这个子序列在 a[]
中对应的下标单调递增
so 用T数组模拟,写一个类似LIS的lower-bound;
若下标小于,update low数组,then update ans;