码迷,mamicode.com
首页 > 其他好文 > 详细

P2757 导弹的召唤(数据加强)

时间:2017-11-27 00:03:55      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:pac   code   传送门   show   print   导弹拦截   tps   ret   ref   

传送门
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));
}

P2757 导弹的召唤(数据加强)

标签:pac   code   传送门   show   print   导弹拦截   tps   ret   ref   

原文地址:http://www.cnblogs.com/FreeRing/p/7900797.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!