二分
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N];
int dp[N];
int n;
const int INF = 0x3f3f3f3f;
void solve()
{
fill(dp, dp + n, INF);
for (int i = 0; i < n; i ++)
*lower_bound(dp, dp + n, a[i]) = a[i];
printf("%d\n", lower_bound(dp, dp + n, INF) - dp);
}
int main()
{
scanf("%d", &n);
for (int i = 0; i < n; i ++)
scanf("%d", &a[i]);
solve();
}