0
0
黄昊轩
新手守护
新手守护
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout) const int Inf=10000000+10; int a[100010],s[100010],l[200010],r[200010]; int main(){ int i,j,k,n,m,b,weizhi=0,flag=0; scanf("%d%d",&n,&b); for(i=1;i<=n;i++){ int x; scanf("%d",&x); if(x==b){ weizhi=i;a[i]=0; } else if(x<b)a[i]=-1; else a[i]=1; } l[n]=1;r[n]=1; for(i=weizhi-1;i>=1;i--){ s[i]=s[i+1]+a[i];l[s[i]+n]++; } for(i=weizhi+1;i<=n;i++){ s[i]=s[i-1]+a[i];r[s[i]+n]++; } int ans=0; for(i=0;i<2*n;i++) ans=ans+l[i]*r[2*n-i]; printf("%d\n",ans); return 0; }
0