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

luoguP1439

时间:2018-03-16 23:48:41      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:define   class   print   post   eof   AC   cstring   else   sed   

技术分享图片
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 100011
int n,w[N],a[N],f[N];
int main()
{
    memset(f,0x7f,sizeof f);
    f[0] = -1000;
    scanf("%d",&n);
    int tmp;
    for(int i = 1;i <= n;i++){
        scanf("%d",&tmp);
        w[tmp] = i;
    }
    for(int i = 1;i <= n;i++){
        scanf("%d",&tmp);
        a[i] = w[tmp];
    }
    for(int i = 1;i <= n;i++){
        int l = 0,r = i - 1,m,ans;
        while(l <= r){
            m = (l + r) / 2;
            if(f[m] < a[i]){
                ans = m;
                l = m + 1;
            }
            else{
                r = m - 1;
            }
        }
        f[ans + 1] = min(a[i],f[ans + 1]);
    }
    for(int i = n;i >= 1;i--){
        if(f[i] != f[N - 1]){
            return printf("%d",i),0;
        }
    }
    return 0;
}
手打二分
技术分享图片
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 100011
int n,w[N],a[N],f[N];
int main()
{
    memset(f,0x7f,sizeof f);
    f[0] = -1000;
    scanf("%d",&n);
    int tmp;
    for(int i = 1;i <= n;i++){
        scanf("%d",&tmp);
        w[tmp] = i;
    }
    for(int i = 1;i <= n;i++){
        scanf("%d",&tmp);
        a[i] = w[tmp];
    }
    for(int i = 1;i <= n;i++){
        int l = 0,r = i - 1,m,ans;
        int* w;
        w = lower_bound(f,f + i,a[i]) - 1;
        ans = w - f;
        f[ans + 1] = min(a[i],f[ans + 1]);
    }
    for(int i = n;i >= 1;i--)
        if(f[i] != f[N - 1])
            return printf("%d",i),0;
    return 0;
}
STL

 

luoguP1439

标签:define   class   print   post   eof   AC   cstring   else   sed   

原文地址:https://www.cnblogs.com/frankying/p/8586309.html

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