LIS(最长上升子序列)

part one

#include <cstdio>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
using namespace std;
template <typename _TP> inline void read(_TP &x){
    x = 0;int f = 1;char c = getchar();
    for(;c < '0' || '9' < c; c = getchar()) if(c == '-') f = -1;
    for(;'0' <= c && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
    x *= f;return;
}
template <typename _TP> inline void print(_TP x){
    if(x < 0) putchar('-'),x = -x;
    if(x > 9) print(x / 10);
    putchar(x % 10 + 48);
    return;
}
#define rg register
#define ll long long
#define r_2(a,b) read(a),read(b)
#define r_3(a,b,c) read(a),read(b),read(c)
#define print_n(a) print(a),puts("")
#define print_(a) print(a),putchar(' ')
#define lowbit(k) (k & -k)
const int inf = 2147483647;
const int maxn = 2e5 + 7;
int n,cnt;
int a[maxn],c[maxn];
struct data{int id,val;}d[maxn];
inline bool cmp(data A,data B){
    if(A.val == B.val) return A.id > B.id;
    return A.val < B.val;
}
inline int query(int k){
    int Ans = 0;
    for(;k; k -= lowbit(k)) Ans = max(Ans,c[k]);
    return Ans;
}
inline void add(int k,int y){
    for(;k <= n; k += lowbit(k)) c[k] = max(c[k],y);
    return;
}
int main()
{
    read(n);
    for(rg int i = 1;i <= n; i++) read(d[i].val),d[i].id = i;
    sort(d + 1,d + 1 + n,cmp);
    for(rg int i = 1;i <= n; i++) add(d[i].id,query(d[i].id) + 1);
    print(query(n));
    return 0;
}
相关文章
相关标签/搜索