nlogn 模板 最长上升
#include<bits/stdc++.h>
using namespace std;
const int N=;
int n,x,y,a[N],num[N],d[N],len;
/*
int binary_search(int i){
int left,right,mid;
left=0,right=len;
while(left<right){
mid = left+(right-left)/2;
if(ans[mid]>=arr[i]) right=mid;
else left=mid+1;
}
return left;
}
*/
int main(){
//LCS转换成LIS
ios::sync_with_stdio(false);
cin>>n;
for(int i=;i<=n;i++)
cin>>x,num[x]=i;
for(int i=;i<=n;i++)
cin>>y,a[i]=num[y]; //nlogn LIS
d[]=a[],len=;
for(int i=;i<=n;i++){
if(a[i]>d[len])
d[++len]=a[i];
else{
//int pos=binary_search(i);
int pos=lower_bound(d,d+len,a[i])-d;
d[pos]=a[i];}
}
printf("%d",len);return ;}
UVa10635,蓝书p66例题27:另一种写法
#include<bits/stdc++.h> using namespace std; const int N=;
const int inf=0x3f3f3f3f; int s[N],g[N],d[N],num[N]; int main(){
int t;scanf("%d",&t);
for(int kase=;kase<=t;kase++){
int N,p,q,x;
scanf("%d%d%d",&N,&p,&q);
memset(num,,sizeof num);
for(int i=;i<=p+;i++){
scanf("%d",&x);
num[x]=i;}
int n=;
for(int i=;i<q+;i++){
scanf("%d",&x);
if(num[x]) s[n++]=num[x];} for(int i=;i<=n;i++) g[i]=inf;
int ans=;
for(int i=;i<n;i++){
int k=lower_bound(g+,g++n,s[i])-g;
d[i]=k;
g[k]=s[i];
ans=max(ans,d[i]);
}printf("Case %d: %d\n",kase,ans);
}return ;
}
ATTENTION:最长不下降,需要a[i]>=d[len]以及 UPPER_bound !!!!