#include <bits/stdc++.h> #define int long long #define cln cout<<"\n---------------\n" using namespace std; constexpr int N = 5e4+7; constexpr int MOD = 1e9+7; int licz (vector <int> T, bool k) { int r = 0, n = T.size(); for (int i=1; i<n; ++i) { if (k) { if (T[i] >= T[i-1]) { r++; T[i] = -1e6+1; } } else { if (T[i] <= T[i-1]) { r++; T[i] = 1e6+1; } } if (k) k = false; else k = true; } return r; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; vector <int> T(n); for (int i=0; i<n; ++i) { cin>>T[i]; } int res = min(licz(T, true), licz(T, false)); cout<<res; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #include <bits/stdc++.h> #define int long long #define cln cout<<"\n---------------\n" using namespace std; constexpr int N = 5e4+7; constexpr int MOD = 1e9+7; int licz (vector <int> T, bool k) { int r = 0, n = T.size(); for (int i=1; i<n; ++i) { if (k) { if (T[i] >= T[i-1]) { r++; T[i] = -1e6+1; } } else { if (T[i] <= T[i-1]) { r++; T[i] = 1e6+1; } } if (k) k = false; else k = true; } return r; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; vector <int> T(n); for (int i=0; i<n; ++i) { cin>>T[i]; } int res = min(licz(T, true), licz(T, false)); cout<<res; return 0; } |