首页 > 其他 > 详细

POJ3903Stock Exchange (LIS)

时间:2019-08-16 21:21:44      阅读:55      评论:0      收藏:0      [点我收藏+]

学了下BIT,炸了。。。

#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("\n\n----------\n\n")
#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 = 100007;

#define int long long
int n;
int a[N], b[N], f[N];
int t[N];
inline void Updata(int x, int val){
    for(; x <= n; x += x & -x) t[x] = Max(t[x], val);
}
inline int Query(int x){
//  int s = 2147483648;
    int s = 0;
    for(; x; x -= x & -x) s = Max(s, t[x]);
    return s;
}
#undef int 
int main(){
#define int long long
    while(~scanf("%lld", &n)){
        R(i,1,n){
            io >> a[i];
//          b[i] = a[i];
        }
//      sort(b + 1, b + n + 1);
//      int len = unique(b + 1, b + n + 1) - b - 1;
//      for(register int i = 1; i <= n; i += 3){
//          t[i] = 0, t[i + 1] = 0, t[i + 2] = 0;
//      }
//      int ans = 0;
//      R(i,1,n){
//          int pos = upper_bound(b + 1, b + len + 1, a[i]) - b;
//          f[i] = f[Query(pos)] + 1;
//          Updata(pos, f[i]);
//          ans = Max(ans, f[i]);
//      }
//      printf("%lld\n", ans);
        int 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("%lld\n", len);
    }
    
    return 0;
} 

HACK lower_bound 和 upper_bound 搞混のCode
10
3 9 8 3 5 7 9 6 4 5

POJ3903Stock Exchange (LIS)

原文:https://www.cnblogs.com/bingoyes/p/11366174.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!