-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path가장 긴 증가하는 부분수열2.cpp
43 lines (36 loc) · 948 Bytes
/
가장 긴 증가하는 부분수열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
#include <iostream>
#include <algorithm>
#pragma warning (disable : 4996)
using namespace std;
int arr[20000];
void update(int i, int v) {
i += (1 << 20);
arr[i] = v;
while (i > 1) {
i /= 2;
arr[i] = max(arr[i * 2], arr[i * 2 + 1]);
}
}
int val(int L, int R, int nodeNum, int nodeL, int nodeR) {
if (R < nodeL || nodeR < L) return 0;
if (L <= nodeL && nodeR <= R) return arr[nodeNum];
int mid = (nodeL + nodeR) / 2;
return max(val(L, R, nodeNum * 2, nodeL, mid), val(L, R, nodeNum * 2 + 1, mid + 1, nodeR));
}
int main() {
int n; cin >> n;
pair<int, int> p[1000001];
for (int i = 0, a; i < n; i++) {
cin >> a;
p[i] = { a,i };
}
sort(p, p + n, [](pair<int, int> p, pair<int, int> q) {
if (p.first != q.first) return p.first < q.first;
return p.second > q.second;
});
for (int i = 0; i < n; i++) {
int temp = val(0, p[i].second, 1, 0, (1 << 20) - 1) + 1;
update(p[i].second, temp);
}
cout << arr[1] << '\n';
}