#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
int main() {
std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
int n;
std::cin >> n;
const int INF = (int)1e9 + 1;
int last = -INF;
int ans = 0;
for(int i = 0; i < n; i++) {
int x;
std::cin >> x;
if(i % 2 == 0) {
if(x > last) {
last = x;
} else {
last = INF;
ans++;
}
} else {
if(x < last) {
last = x;
} else {
last = -INF;
ans++;
}
}
}
std::cout << ans << '\n';
}
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 | #include <iostream> #include <vector> #include <chrono> #include <random> #include <cassert> std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count()); int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n; std::cin >> n; const int INF = (int)1e9 + 1; int last = -INF; int ans = 0; for(int i = 0; i < n; i++) { int x; std::cin >> x; if(i % 2 == 0) { if(x > last) { last = x; } else { last = INF; ans++; } } else { if(x < last) { last = x; } else { last = -INF; ans++; } } } std::cout << ans << '\n'; } |
English