zoukankan      html  css  js  c++  java
  • LuoguP1020 导弹拦截 (LIS)

    最长不降和单升

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #define R(a,b,c) for(register int  a = (b); a <= (c); ++ a)
    #define nR(a,b,c) for(register int  a = (b); a >= (c); -- a)
    #define Max(a,b) ((a) > (b) ? (a) : (b))
    #define Min(a,b) ((a) < (b) ? (a) : (b))
    #define Fill(a,b) memset(a, b, sizeof(a))
    #define Abs(a) ((a) < 0 ? -(a) : (a))
    #define Swap(a,b) a^=b^=a^=b
    #define ll long long
    
    #define ON_DEBUG
    
    #ifdef ON_DEBUG
    
    #define D_e_Line printf("
    
    ----------
    
    ")
    #define D_e(x)  cout << #x << " = " << x << endl
    #define Pause() system("pause")
    #define FileOpen() freopen("in.txt","r",stdin);
    
    #else
    
    #define D_e_Line ;
    #define D_e(x)  ;
    #define Pause() ;
    #define FileOpen() ;
    
    #endif
    
    struct ios{
        template<typename ATP>ios& operator >> (ATP &x){
            x = 0; int f = 1; char c;
            for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-')  f = -1;
            while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
            x*= f;
            return *this;
        }
    }io;
    using namespace std;
    
    const int N = 1000007;
    
    int a[N], b[N];
    int main(){
    	int n = 0;
    	while(~scanf("%d", &a[++n]));
    	--n; //!
    	
    	int len = 1;
    	b[1] = a[1];
    	R(i,2,n){
    		if(a[i] <= b[len]) b[++len] = a[i];
    		else{
    			*upper_bound(b + 1, b + len + 1, a[i], greater<int>()) = a[i]; //! greater<int>()
    		}
    	}
    	printf("%d
    ", len);
    	
    	len = 1;
    	b[1] = a[1];
    	R(i,2,n){
    		if(a[i] > b[len]) b[++len] = a[i];
    		else{
    			*lower_bound(b + 1, b + len + 1, a[i]) = a[i];
    		}
    	}
    	printf("%d", len);
    	
    	return 0;
    } 
    
  • 相关阅读:
    Java集合中迭代器
    java 基础归纳总结(三)
    java 基础归纳总结(二)
    java 基础归纳总结(一)
    python之hashlib模块
    python之configparser模块
    Python之time模块
    python之os模块
    python之random模块
    python generator(生成器)
  • 原文地址:https://www.cnblogs.com/bingoyes/p/11365958.html
Copyright © 2011-2022 走看看