```
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 100010;
int f[N]; //f数组存储的是最长不上升序列(注意不是子序列)
int g[N]; //g数组存储的是最长上升序列(注意不是子序列)
int h[N];
int n;
int main()
{
while (cin >> h[++ n]);
n --;
int res = 1, cnt = 1;
f[1] = g[1] = h[1];
for (int i = 2; i <= n; i ++ )
{
if (h[i] <= f[res]) f[++ res] = h[i];
else
{
int k = upper_bound(f + 1, f + res + 1, h[i], greater<int>()) - f;
f[k] = h[i];
}
if (h[i] > g[cnt]) g[++ cnt] = h[i];
else
{
int k = lower_bound(g + 1, g + cnt + 1, h[i]) - g;
g[k] = h[i];
}
}
printf("%d\n%d\n", res, cnt);
return 0;
}
```
给我个关注awa
by EARS_TURE @ 2024-04-27 16:07:52