求助!不知道哪里有bug

P1439 【模板】最长公共子序列

qpdk777 @ 2020-04-19 22:31:11

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

int n,t,a[100010],dp[100010],ans;

int binary(int l,int r,int p){
    if(l == r) return l;
    int mid = (l+r)>>1;
    if(dp[mid] <= p)
        return binary(mid+1,r,p);
    else
        return binary(l,mid,p);
}

int main(){
    ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
    cin>>n;
    for(int i = 1;i <= n; ++i){
        cin>>t;
        a[t] = i;
    }
    for(int i = 1; i <= n; ++i)
        cin>>t;
    for(int i = 1;i <= n; ++i){
        if(a[i] > dp[ans]){
            dp[++ans] = a[i];
            continue;
        }
        int pt = binary(1,ans,a[i]);
        dp[pt] = a[i];
    }
    cout<<ans<<endl;

    return 0;
}

求各位大佬看看,是不是二分查找还是别的什么有什么问题


|