From acccd2fd72100ecc4e8aa8429cca69b852ef0d96 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Tue, 24 Nov 2020 21:28:41 +0800 Subject: [PATCH] =?UTF-8?q?P1020=20=E5=AF=BC=E5=BC=B9=E6=8B=A6=E6=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R42449521 --- problem/P1020/P1020.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 problem/P1020/P1020.cpp diff --git a/problem/P1020/P1020.cpp b/problem/P1020/P1020.cpp new file mode 100644 index 00000000..9e104f54 --- /dev/null +++ b/problem/P1020/P1020.cpp @@ -0,0 +1,29 @@ +#include + +using namespace std; + +int n, l1, l2, a[100005], d1[100005], d2[100005]; + +int main() { + while (cin >> a[++n]); + n--; + d1[++l1] = d2[++l2] = a[1]; + for (int i = 2; i <= n; i++) { + if (d1[l1] >= a[i]) { + d1[++l1] = a[i]; + } + else { + int* it = upper_bound(d1 + 1, d1 + 1 + l1, a[i], greater()); + *it = a[i]; + } + if (d2[l2] < a[i]) { + d2[++l2] = a[i]; + } + else { + int* it = lower_bound(d2 + 1, d2 + 1 + l2, a[i], less()); + *it = a[i]; + } + } + cout << l1 << endl << l2 << endl; + return 0; +}