传送门
LIS的O(nlgn)模板题。加强“导弹拦截”
#include <cstdio>
#include <cstring>
#include <algorithm>
#define INF 0x3f3f3f3f
using namespace std;
bool cmp(int x,int y) { return x>=y;}
int ulis(int *dp,const int *a,int n) {
for(int i=0; i<n; ++i) dp[i]=-INF;
for(int i=0; i<n; ++i) *upper_bound(dp,dp+n,a[i],cmp)=a[i];
return lower_bound(dp,dp+n,-INF,cmp2)-dp;
}
int lis(int *dp,const int *a,int n) {
for(int i=0; i<n; ++i) dp[i]=INF;
for(int i=0; i<n; ++i) *lower_bound(dp,dp+n,a[i])=a[i];
return lower_bound(dp,dp+n,INF)-dp;
}
int n,a[300001],tmp[300001];
int main() {
while(~scanf("%d",&a[n])) n++;
printf("%d\n%d\n",ulis(tmp,a,n),lis(tmp,a,n));
}
时间: 2024-10-31 18:19:08