求助

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

zxh923 @ 2024-10-07 11:34:02

#include<bits/stdc++.h> 
#define int long long
#define N 100005
#define pii pair<int,int>
#define x first
#define y second
#define mod 998244353
#define pct __builtin_popcount
#define inf 2e18
using namespace std;
int T=1,n,f[N];
pii a[N];
struct bit{
    int c[N];
    bit(){
        memset(c,0,sizeof c);
    }
    int lowbit(int x){
        return x&-x;
    }
    void modify(int x,int v){
        while(x<=n){
            c[x]=max(c[x],v);
            x+=lowbit(x);
        }
    }
    int qry(int x){
        int res=0;
        while(x){
            res=max(res,c[x]);
            x-=lowbit(x);
        }
        return res;
    }
}b;
void solve(int cs){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].x;
    }
    for(int i=1;i<=n;i++){
        cin>>a[i].y;
    }
    sort(a+1,a+n+1);
    int res=0;
    for(int i=1;i<=n;i++){
        f[i]=b.qry(a[i].y-1)+1;
        b.modify(a[i].y,f[i]);
        res=max(res,f[i]);
    }
    cout<<res;
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
//  cin>>T;
    for(int cs=1;cs<=T;cs++){
        solve(cs);
    }
    return 0;
}

为什么按 a 排序后的 b 的 LIS 这样求会只有30分?


|