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

博客详细介绍了jzoj.4810道路规划题目,包括题目描述、输入输出格式、样例输入输出以及数据约束。通过分析,博主探讨了解题思路,并给出了相应的算法代码实现。
3464

被折叠的 条评论
为什么被折叠?



