zoukankan      html  css  js  c++  java
  • luoguP1439

    #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
  • 相关阅读:
    Code Forces Gym 100886J Sockets(二分)
    CSU 1092 Barricade
    CodeChef Mahesh and his lost array
    CodeChef Gcd Queries
    CodeChef GCD2
    CodeChef Sereja and LCM(矩阵快速幂)
    CodeChef Sereja and GCD
    CodeChef Little Elephant and Balance
    CodeChef Count Substrings
    hdu 4001 To Miss Our Children Time( sort + DP )
  • 原文地址:https://www.cnblogs.com/frankying/p/8586309.html
Copyright © 2011-2022 走看看