P1627 [CQOI2009] Median

Description

Given a permutation of $1,2,...,n$, count how many contiguous subsequences of odd length have the median equal to $b$. The median is the number that lies in the middle after sorting all elements in nondecreasing order.

Input Format

The first line contains two positive integers $n$ and $b$. The second line contains a permutation of $1,2,...,n$.

Output Format

Output a single integer: the number of contiguous subsequences whose median is $b$.

Explanation/Hint

#### Constraints For $30\%$ of the testdata, $n \le 100$; For $60\%$ of the testdata, $n \le 1000$; For $100\%$ of the testdata, $n \le 100000,1 \le b \le n$。 Translated by ChatGPT 5