-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.BinarySearch.cpp
More file actions
40 lines (40 loc) · 1.08 KB
/
1.BinarySearch.cpp
File metadata and controls
40 lines (40 loc) · 1.08 KB
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
#include <iostream>
#include <vector>
// DONE
// LIS
int LeastIncreaseSubstring() {
std::cin.tie(NULL);
std::cout.tie(NULL);
std::ios::sync_with_stdio(false);
int n;
std::cin >> n;
std::vector<int> array(n);
for(int i = 0 ; i < n ; i++) {
std::cin >> array[i];
}
std::vector<int> answer(n, 1);
std::vector<int> xArray;
std::vector<int> xAnswer;
int num = -1;
for(int i = 0 ; i < n ; i++) {
if(i == 0) {
xArray.push_back(array[i]);
xAnswer.push_back(answer[i]);
num ++;
}
else {
if(xArray[num] < array[i]) {
xArray.push_back(array[i]);
answer[i] = xAnswer[num] + 1;
xAnswer.push_back(answer[i]);
num++;
}
else {
int changeIndex = std::lower_bound(xArray.begin(), xArray.end(), array[i]) - xArray.begin();
answer[i] = xAnswer[changeIndex];
xArray[changeIndex] = array[i];
}
}
}
std::cout << xAnswer[num] << "\n";
}