1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<ctime> 5 #include<iostream> 6 #include<algorithm> 7 #include<queue> 8 #include<set> 9 #define inf (0x7fffffff) 10 #define l(a) ((a)<<1) 11 #define r(a) ((a)<<1|1) 12 #define b(a) (1<<(a)) 13 #define rep(i,a,b) for(int i=a;i<=(b);i++) 14 #define clr(a) memset(a,0,sizeof(a)) 15 typedef long long ll; 16 typedef unsigned long long ull; 17 using namespace std; 18 int readint(){ 19 int t=0,f=1;char c=getchar(); 20 while(!isdigit(c)){ 21 if(c==‘-‘) f=-1; 22 c=getchar(); 23 } 24 while(isdigit(c)){ 25 t=(t<<3)+(t<<1)+c-‘0‘; 26 c=getchar(); 27 } 28 return t*f; 29 } 30 const int maxn=100009; 31 int n,ans,a[maxn],b[maxn],p[maxn],d[maxn],g[maxn]; 32 int main(){ 33 //freopen("#input.txt","r",stdin); 34 //freopen("#output.txt","w",stdout); 35 n=readint(); 36 rep(i,1,n) a[i]=readint(); 37 rep(i,1,n) b[i]=readint(); 38 rep(i,1,n) p[a[i]]=i; 39 rep(i,1,n) b[i]=p[b[i]]; 40 d[1]=1;g[1]=a[1]; 41 rep(i,1,n){ 42 if(b[i]>g[ans]){ 43 g[++ans]=b[i]; 44 d[i]=ans; 45 continue; 46 } 47 int t=lower_bound(g+1,g+ans+1,b[i])-g; 48 g[t]=b[i]; 49 d[i]=t; 50 } 51 cout<<ans<<endl; 52 //fclose(stdin); 53 //fclose(stdout); 54 return 0; 55 }