Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- //----------------------------------
- constexpr int NMAX = 1e5 + 3;
- int f[NMAX];
- int dp[NMAX];
- signed main() {
- int a, b;
- cin >> a >> b;
- int n = 0;
- for (int x, i = 0; i < b - a + 1; i++) {
- cin >> x;
- if (x != f[n]) {
- f[++n] = x;
- }
- }
- dp[1] = dp[2] = 1;
- for (int i = 3; i <= n; i++) {
- bool mono = false;
- mono |= f[i] > f[i - 1] && f[i - 1] > f[i - 2];
- mono |= f[i] < f[i - 1] && f[i - 1] < f[i - 2];
- if (mono) {
- dp[i] = dp[i - 1];
- } else {
- dp[i] = dp[i - 1] + 1;
- }
- }
- cout << dp[n] << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement