0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-16 20:25:24 +00:00

896. 最长上升子序列 II

https://www.acwing.com/problem/content/submission/code_detail/8868075/
This commit is contained in:
Baoshuo Ren 2021-11-16 17:33:56 +08:00 committed by Baoshuo Ren
parent a9de927b3a
commit 94532334c7
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

28
AcWing/896/896.cpp Normal file
View File

@ -0,0 +1,28 @@
#include <bits/stdc++.h>
using namespace std;
int n, a[100005], q[100005], len;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
q[0] = 0xc0c0c0c0;
for (int i = 0; i < n; i++) {
int l = 0, r = len + 1;
while (l < r) {
int mid = l + r >> 1;
if (q[mid] < a[i]) {
l = mid + 1;
} else {
r = mid;
}
}
q[l] = a[i];
len = max(len, l);
}
cout << len << endl;
return 0;
}