#P1627. [CQOI2009] 中位数

[CQOI2009] 中位数

Description

Given a permutation of 1,2,...,n1,2,...,n, count how many contiguous subsequences of odd length have the median equal to bb. 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 nn and bb. The second line contains a permutation of 1,2,...,n1,2,...,n.

Output Format

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

7 4
5 7 2 4 3 1 6 
4

Hint

Constraints

For 30%30\% of the testdata, n100n \le 100

For 60%60\% of the testdata, n1000n \le 1000

For 100%100\% of the testdata, n100000,1bnn \le 100000,1 \le b \le n

Translated by ChatGPT 5