#P1627. [CQOI2009] 中位数

    ID: 2420 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>数学2009重庆各省省选排序

[CQOI2009] 中位数

Problem 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