FXJFXJ @ 2023-11-19 20:48:34
我的代码用upper_bound和lower_bound都能过,哪个才是真正 正确的呢?
#include <bits/stdc++.h>
using namespace std;
const int maxn=100005;
int a[maxn],lower[maxn],idx[maxn];
int LIS(int n) {
int index=0;
for(int i=1;i<=n;i++) {
if(index==0||a[i]>lower[index-1]){
lower[index++]=a[i];
}else {
int pos=lower_bound(lower,lower+index,a[i])-lower;
lower[pos]=a[i];
}
}
return index;
}
int main() {
int n,temp;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++) {cin>>temp;idx[temp]=i;}
for(int i=1;i<=n;i++) {a[i]=idx[a[i]];}
int ans=LIS(n);
cout<<ans<<endl;
}
by Wu1hong2shen3_why_42 @ 2023-11-19 20:52:42
@FXJFXJ
by FXJFXJ @ 2023-11-19 21:08:34
@Wu1hong2shen3 噢噢噢噢,谢谢!