rt.
数据有问题吧,第一个数据应该1次就够了。
10
-5 -4 -3 3 0 0 1 2 -4 2
若不对,求调
#include<bits/stdc++.h>
using namespace std;
int n;
long long a[100005];
bool check1() {
vector<int> pos;
for (int i = 2; i <= n - 1; i += 2) {
if ((a[i] - a[i - 1]) * (a[i] - a[i + 1]) < 0) {
pos.push_back(i);
}
}
if (pos.size() > 2) {
return false;
}
if (pos.size() == 2) {
int l = pos[0];
int r = pos[1];
if (r - l > 2) {
return false;
}
int mid = (l + r) / 2;
return (a[mid] - a[l]) * (a[mid] - a[r]) > 0;
}
return true;
}
int main() {
while (cin >> n) {
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
if (check1() )cout << "Yes" << '\n';
else {
cout << "No" << '\n';
}
}
return 0;
}