mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-25 05:11:59 +00:00
P1020 导弹拦截
R42449521
This commit is contained in:
parent
9e1a5ed3e7
commit
acccd2fd72
29
problem/P1020/P1020.cpp
Normal file
29
problem/P1020/P1020.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user