This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
const int N = 1e6 + 69;
int n, a[N], dp[N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1;i <= n;i++) {
cin >> a[i];
dp[i] = 1e9;
}
set<int> st;
dp[0] = 0;
for (int i = 1;i <= n;i++) {
dp[i] = min(dp[i], dp[i - 1] + 1);
auto manji = st.upper_bound(a[i]);
auto veci = st.lower_bound(a[i]);
int x, y;
if (manji == st.begin())
x = -1;
else
x = *--manji;
if (veci == st.end())
y = 1e9;
else
y = *veci;
int j = i + 1;
while (j <= n && a[j] >= x && a[j] <= y && a[j] >= a[j - 1])
j++;
for (int k = i;k < j;k++)
dp[k] = min(dp[k], dp[i - 1] + 1);
st.insert(a[i]);
}
cout << dp[n];
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |