思路:A要赢的大前提就是当前x是一个波峰。
因为如果是一个直线单调的话如1 2 3 4 5(或者5 4 3 2 1),不管A选哪个位置,B直接在他下一个位置封死,A就直接GG。
现在考虑波峰的时候,那A就有两条路可以走,走左边或者走右边都可以(这个时候B就不能直接封死A了)。但是如果B能在别的地方挑一条比这两条路还长的路,那A还是输。当B选不到更长的路的时候,就会尽量的恶心A,走两条路中较长的那一条,这个时候A走较短的话必输,所以AB这时候必须相向而行。这个时候这条路的长度是奇数的话A就能赢了,且是唯一的一种赢法。
看看图解吧。
view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '
'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
ll n;
ll a[maxn];
ll dp[maxn][2];
int main()
{
n = read();
rep(i,1,n) a[i] = read();
dp[1][0] = dp[n][1] = 1;
map<ll,ll> cnt1;
map<ll,ll> cnt2;
ll ma = 0;
rep(i,2,n)
{
if(a[i]>a[i-1]) dp[i][0] = dp[i-1][0] + 1;
else dp[i][0] = 1;
}
per(i,n-1,1)
{
if(a[i]>a[i+1]) dp[i][1] = dp[i+1][1] + 1;
else dp[i][1] = 1;
}
rep(i,1,n)
{
cnt1[dp[i][0]]++;
cnt2[dp[i][1]]++;
ma = max(ma,max(dp[i][0],dp[i][1]));
}
ll ans = 0;
rep(i,1,n)
{
if(dp[i][0]==1||dp[i][1]==1) continue;
ll ma1 = max(dp[i][0], dp[i][1]);
ll mi1 = min(dp[i][0],dp[i][1]);
if(ma>ma1||ma==ma1&&(cnt1[ma]>1||cnt2[ma]>1)||(ma==ma1&&(cnt1[ma]==1&&cnt2[ma]==1&&ma%2==0)) ) continue;
if(ma1-mi1<=0) ans++;
}
cout<<ans<<endl;
return 0;
}