解题思路:对于A来说,A只能往下寻找。对于B来说,B只能往上寻找。所以A只能选择某个顶点,如果选择一个单调递增或者单调递减的,A选择了之后,B就可以直接拦截。此时A要选择一个单调递增或者单调递减长度最长的,要不然B选择的长度会是最长的,那么B就必胜。只有在单调长度最长且为奇数,并且顶点两边单调性相反,A是必胜。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lf;
typedef unsigned long long ull;
typedef pair<ll,int>P;
const int inf = 0x7f7f7f7f;
const ll INF = 1e16;
const int N = 1e5+10;
const ull base = 131;
const ll mod = 1e9+7;
const double PI = acos(-1.0);
const double eps = 1e-4;
inline int read(){
int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){
if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){
x=x*10+ch-'0';ch=getchar();}return x*f;}
inline string readstring(){
string str;char s=getchar();while(s==' '||s=='\n'||s=='\r'){
s=getchar();}while(s!=' '&&s!='\n'&&s!='\r'){
str+=s;s=getchar();}return str;}
int random(int n){
return (int)(rand()*rand())%n;}
void writestring(string s){
int n = s.size();for(int i = 0;i < n;i++){
printf("%c",s[i]);}}
ll fast_power(ll a,ll p){
ll ans = 1;
while(p){
if(p&1) ans = (ans*a)%mod;
p >>= 1;
a = (a*a)%mod;
}
return ans;
}
int a[N];
int l[N],r[N];
int main(){
int n = read();
for(int i = 1;i <= n;i++){
a[i] = read();
}
for(int i = 1;i <= n;i++){
if(a[i] > a[i-1]){
l[i] = l[i-1]+1;
}else l[i] = 1;
}
for(int i = n;i >= 1;i--){
if(a[i] > a[i+1]){
r[i] = r[i+1]+1;
}else r[i] = 1;
}
int ma = 0,num = 0,id = 0;
for(int i = 1;i <= n;i++){
if(ma < l[i] || ma < r[i]){
ma = max(l[i],r[i]);
num = 1;
id = i;
}else if(ma == l[i] || ma == r[i])num++;
}
if(num==1&&ma%2&&l[id]==r[id]){
puts("1");
}else puts("0");
return 0;
}