#P6334. Odd Length Substring Median
Odd Length Substring Median
Odd Length Substring Median
Given a permutation \(a_1, a_2, \dots, a_n\) of the numbers from 1 to n, your task is to count how many substrings of odd length have a median equal to \(B\).
Definition of substring: A substring is defined as a contiguous segment obtained by removing zero or more elements from the beginning and/or the end of the permutation.
Definition of median: The median of a sequence is the middle element after sorting the sequence in non-decreasing order.
inputFormat
The input consists of two lines. The first line contains two integers \(n\) and \(B\) (with \(1 \leq B \leq n\)), where \(n\) is the length of the permutation and \(B\) is the target median value. The second line contains \(n\) distinct integers representing the permutation, separated by spaces.
outputFormat
Output a single integer representing the number of substrings of odd length whose median is equal to \(B\).
sample
3 2
1 2 3
2