【NOIP2016提高A组五校联考1】道路规划

Description

【NOIP2016提高A组五校联考1】道路规划_第1张图片

Solution

仔细的推敲了一下题目,如果a[i]

Code

#include
#include
#include
#include
#include
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=100007;
int i,j,k,l,t,n,m,ans;
int f[maxn],r,mid,c[maxn];
struct node{
    int a,b;
}a[maxn];
bool cmp(node x,node y){
    return x.aint main(){
//  freopen("fan.in","w",stdout);
    scanf("%d",&n);
    fo(i,1,n)scanf("%d",&k),a[k].a=i;
    fo(i,1,n)scanf("%d",&k),a[k].b=i;
    sort(a+1,a+1+n,cmp);
    f[ans=1]=a[1].b;
    fo(i,2,n){
        if(a[i].belse{
            l=1,r=ans;
            while(l2;
                if(f[mid]>a[i].b)l=mid+1;else r=mid;
            }
            f[l]=a[i].b;
        }
    }
    printf("%d\n",ans);
}

你可能感兴趣的:(noip,树状数组)