题目描述
Problem Description
Given a permutation \(a_1, \dots, a_n\) of length \(n\) where each element is between \(1\) and \(n\), find the number of odd-length substrings whose median is \(B\).
-
Substring Definition: A substring is obtained by removing some (possibly none) elements from the beginning and/or end of the permutation.
-
Median Definition: The median of a sequence is the number that would be in the middle if the sequence were sorted in ascending order.
Input Format
The first line contains two integers \(n\) and \(B\).
The second line contains \(n\) integers, representing a permutation of \(1\) to \(n\).
Output Format
Output the number of odd-length substrings with the median \(B\).
Sample Input and Output
Sample Input #1
5 4
1 2 3 4 5
Sample Output #1
2
Sample Input #2
6 3
1 2 4 5 6 3
Sample Output #2
1
Sample Input #3
7 4
5 7 2 4 3 1 6
Sample Output #3
4
Notes
Sample #3 Explanation
All possible cases: 4, 7 2 4, 5 7 2 4 3, 5 7 2 4 3 1 6.
Data Constraints
For \(100\%\) of the data, \(1 \le n \le 10^5\), \(1 \le B \le n\).
Notes
Translated from COCI2007-2008 CONTEST #1 T5 SREDNJI
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分