提交时间:2024-03-23 00:21:51
运行 ID: 139292
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 005; int a[N]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; if (n <= 2) { cout << n << endl; return 0; } int res = 1, u = 1, d = 2, s = 0; for (int i = 2; i <= n; i++) { if (i == 2) { if (a[i] > a[i - 1]) { s = d; res++; } else if (a[i] < a[i - 1]) { s = u; res++; } } else if (s == u) { if (a[i] > a[i - 1]) { s = d; res++; } } else if (s == d) { if (a[i] < a[i - 1]) { s = u; res++; } } } cout << res << endl; return 0; }