题目链接:最长上升子序列 II
#include
#include
using namespace std;
const int N = 100010;
int n;
int a[N];
// 不同长度上升子序列的结尾的最小值
int q[N];
int main()
{
cin >> n;
for(int i = 0; i < n; i ++) cin >> a[i];
q[0] = -2e9;
// 上升子序列的长度
int len = 0;
for(int i = 0; i < n; i ++)
{
int l = 0, r = len;
while(l < r)
{
int mid = l + r + 1 >> 1;
if(q[mid] < a[i]) l = mid;
else r = mid - 1;
}
len = max(len, r + 1);
q[r + 1] = a[i];
}
cout << len << endl;
return 0;
}