- 中位数
- 2016-11-14 13:26:14 @
//四个点未过
#include<iostream>
#include<stdio.h>
#include<map>
using namespace std;
int n,a,tot=0,XX[100500]={0},b;
map<int ,int>X1,X2;
int main()
{
cin>>n>>a;
for(int i=1;i<=n;i++)
{ cin>>XX[i];
if(XX[i]<a)
{
XX[i]=XX[i-1]-1;
//cout<<XX[0][i]<<" "<<XX[0][i-1];
}
else if(XX[i]>a)
{
XX[i]=XX[i-1]+1;
}
else
{
XX[i]=XX[i-1];
b=1;
}
if(b==0)
{
if(i%2==0)
X1[XX[i]]++;
else X2[XX[i]]++;
//cout<<XX[i]<<" "<<X2[XX[i]]<<endl;
}
else
{
if(XX[i]==0&&(i%2==1))
{
tot++;
// cout<<i<<endl;
}
else if(i%2==0)
{
tot+=X2[XX[i]];
}
else
{
tot+=X1[XX[i]];
//cout<<X1[XX[i]]<<endl;
}
}
}
//cout<<X2[-1];
// for(int i=-n;i<=n;i++)
// cout<<X2[i]<<endl;
cout<<tot;
return 0;
}