//贪心
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 100010;
int n;
vector<int> stk;
int arr[N];
int main()
{
cin>>n;
for (int i = 0; i < n; i ++ ) scanf("%d", &arr[i]);
stk.push_back(arr[0]);
for(int i=1;i<n;i++)
{
if(arr[i]>stk.back())
{
stk.push_back(arr[i]);
}
else
{
*lower_bound(stk.begin(),stk.end(),arr[i])=arr[i];
}
}
cout<<stk.size();
return 0;
}
回顾一下lower_bound()的用法,传进去三个参数
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 100010;
int arr[N];
vector<int> v;
int n;
int main()
{
cin>>n;
for(int i=1;i<=n;i++) scanf("%d", &arr[i]);
v.push_back(arr[1]);
for(int i=2;i<=n;i++)
{
if(arr[i]>v.back())
{
v.push_back(arr[i]);
}
else
{
*lower_bound(v.begin(),v.end(),arr[i])=arr[i];
}
}
cout<<v.size();
}