-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlongest_increasing_subsequence.cpp
57 lines (51 loc) · 1.22 KB
/
longest_increasing_subsequence.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <algorithm>
#include <numeric>
#include <iterator>
#include <iostream>
#include <bitset>
#include <deque>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <climits>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<long long,long long> pii;
typedef vector<long long> vi;
typedef vector<vector<pair<long long,long long>>> vvpii;
typedef unordered_set<int> uset;
#define pb push_back
#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
int LIS(vi a) {
int lena = a.size();
vector<int> table(lena+1, INT_MAX);
table[0] = INT_MIN;
for (int i = 0; i < lena; i++) {
int j = upper_bound(table.begin(), table.end(), a[i]) - table.begin();
if (table[j-1] < a[i] && a[i] < table[j])
table[j] = a[i];
}
int out = 0;
for (int i = 0; i <= lena; i++) {
if (table[i] < INT_MAX)
out = i;
}
return out;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N;
scan(N);
vi A(N);
for(int i = 0; i < N; i++) {
scan(A[i]);
}
cout << LIS(A);
}