bzoj1303

时间:2023-11-23 08:09:26

首先找到b的位置x,要求满足b为中位数的数列
把比b大的设为1,比b小设为-1
则数列满足条件则x 左边的的和+x右边的和=0 
然后应该就很好搞了

 var a,l,r,s:array[..] of longint;
i,n,m,x,k,ans:longint;
begin
readln(n,m);
for i:= to n do
begin
read(x);
if x=m then k:=i
else if x>m then a[i]:=
else a[i]:=-;
end;
l[n]:=;
r[n]:=;
for i:=k- downto do
begin
s[i]:=s[i+]+a[i];
inc(l[s[i]+n]);
end;
for i:=k+ to n do
begin
s[i]:=s[i-]+a[i];
inc(r[s[i]+n]);
end;
for i:= to *n- do
ans:=ans+l[i]*r[*n-i];
writeln(ans);
end.