代码仅解决第一问
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int xx = 100010;
const int INF = 0x7ffffff;
int n, m[xx], ans = -1, f[xx], a[xx];
int main()
{
while (cin >> (m[++n]));
//--n;
memset(a, 0x3f, sizeof(a));
for (int i = 1; i <= n; ++i)
{
int j = lower_bound(a, a + n, m[i]) - a;
f[i] = j + 1;
ans = max(ans, f[i]);
a[f[i]] = m[i];
}
cout << ans;
return 0;
}