mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-08 15:18:46 +00:00
896. 最长上升子序列 II
https://www.acwing.com/problem/content/submission/code_detail/8868075/
This commit is contained in:
parent
a9de927b3a
commit
94532334c7
28
AcWing/896/896.cpp
Normal file
28
AcWing/896/896.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user