-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12015_가장긴증가하는부분수열2.cpp
78 lines (56 loc) · 958 Bytes
/
12015_가장긴증가하는부분수열2.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//12015
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
vector<int> v;
int arr[1000001];
int N;
vector<int>result;
void binery_search(int num) {
int ret = 1000000;
int start = 0;
int end = result.size() - 1;
while (start <= end) {
int mid = (start + end) / 2;
int value = result[mid];
if (value >= num) {
if (ret > mid) {
ret = mid;
}
end = mid - 1;
}
else {
start = mid + 1;
}
}
result[ret] = num;
return;
}
void insert() {
result.push_back(arr[0]);
for (int i = 1; i < N; i++) {
if (result.back() < arr[i]) {
result.push_back(arr[i]);
}
else if (result.back() == arr[i]) {
continue;
}
else {
binery_search(arr[i]);
}
}
return;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N;
for (int i = 0; i < N; i++) {
cin >> arr[i];
}
insert();
cout << result.size();
return 0;
}