#include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define N 100011 int n,w[N],a[N],f[N]; int main() { memset(f,0x7f,sizeof f); f[0] = -1000; scanf("%d",&n); int tmp; for(int i = 1;i <= n;i++){ scanf("%d",&tmp); w[tmp] = i; } for(int i = 1;i <= n;i++){ scanf("%d",&tmp); a[i] = w[tmp]; } for(int i = 1;i <= n;i++){ int l = 0,r = i - 1,m,ans; while(l <= r){ m = (l + r) / 2; if(f[m] < a[i]){ ans = m; l = m + 1; } else{ r = m - 1; } } f[ans + 1] = min(a[i],f[ans + 1]); } for(int i = n;i >= 1;i--){ if(f[i] != f[N - 1]){ return printf("%d",i),0; } } return 0; }
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define N 100011 int n,w[N],a[N],f[N]; int main() { memset(f,0x7f,sizeof f); f[0] = -1000; scanf("%d",&n); int tmp; for(int i = 1;i <= n;i++){ scanf("%d",&tmp); w[tmp] = i; } for(int i = 1;i <= n;i++){ scanf("%d",&tmp); a[i] = w[tmp]; } for(int i = 1;i <= n;i++){ int l = 0,r = i - 1,m,ans; int* w; w = lower_bound(f,f + i,a[i]) - 1; ans = w - f; f[ans + 1] = min(a[i],f[ans + 1]); } for(int i = n;i >= 1;i--) if(f[i] != f[N - 1]) return printf("%d",i),0; return 0; }