0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-19 16:25:25 +00:00
OI-codes/Luogu/P1020/P1020.cpp

30 lines
665 B
C++
Raw Permalink Normal View History

2020-11-24 13:28:41 +00:00
#include <bits/stdc++.h>
using namespace std;
int n, l1, l2, a[100005], d1[100005], d2[100005];
int main() {
2021-11-19 09:01:13 +00:00
while (cin >> a[++n])
;
2020-11-24 13:28:41 +00:00
n--;
d1[++l1] = d2[++l2] = a[1];
for (int i = 2; i <= n; i++) {
if (d1[l1] >= a[i]) {
d1[++l1] = a[i];
2021-11-19 09:01:13 +00:00
} else {
2020-11-24 13:28:41 +00:00
int* it = upper_bound(d1 + 1, d1 + 1 + l1, a[i], greater<int>());
*it = a[i];
}
if (d2[l2] < a[i]) {
d2[++l2] = a[i];
2021-11-19 09:01:13 +00:00
} else {
2020-11-24 13:28:41 +00:00
int* it = lower_bound(d2 + 1, d2 + 1 + l2, a[i], less<int>());
*it = a[i];
}
}
2021-11-19 09:01:13 +00:00
cout << l1 << endl
<< l2 << endl;
2020-11-24 13:28:41 +00:00
return 0;
}