0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-09 22:38:47 +00:00

P1020 导弹拦截

R42449521
This commit is contained in:
Baoshuo Ren 2020-11-24 21:28:41 +08:00 committed by Baoshuo Ren
parent 9e1a5ed3e7
commit acccd2fd72
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

29
problem/P1020/P1020.cpp Normal file
View File

@ -0,0 +1,29 @@
#include <bits/stdc++.h>
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<int>());
*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<int>());
*it = a[i];
}
}
cout << l1 << endl << l2 << endl;
return 0;
}