题目
Description
Input
Output
Sample Input
5
1 4 5 2 3
3 4 2 1 5
Sample Output
3
Data Constraint
Hint
分析
CODE
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
struct llx{
int x,y;
}a[100010];
int n,tot,maxn,f[100010];
bool cmp(llx x,llx y){
return x.x<y.x;
}
int main(){
scanf("%d",&n);
for (int i=1;i<=n;i++){
int m;
scanf("%d",&m);
a[m].x=i;
}
for (int i=1;i<=n;i++){
int m;
scanf("%d",&m);
a[m].y=i;
}
sort(a+1,a+n+1,cmp);
tot=1;
f[tot]=a[1].y;
for (int i=2;i<=n;i++){
if (f[tot]>a[i].y){
tot++;
f[tot]=a[i].y;
}
else{
int l=1,r=tot;
while(l<r){
int mid=(l+r)/2;
if(f[mid]>a[i].y) l=mid+1;
else r=mid;
}
f[l]=a[i].y;
}
}
printf("%d\n",tot);
return 0;
}