#P6334. [COCI 2007/2008 #1] SREDNJI
[COCI 2007/2008 #1] SREDNJI
Problem Description
Given a permutation of with length , find how many subarrays of odd length have median .
-
Definition of subarray: the remaining sequence after deleting some numbers from the beginning (possibly none) and some numbers from the end (possibly none) of this permutation.
-
Definition of median: after sorting a sequence in increasing order, the number that is in the middle.
Input Format
The first line contains two integers .
The second line contains integers, a permutation of .
Output Format
Output the number of odd-length subarrays whose median is .
5 4
1 2 3 4 5
2
6 3
1 2 4 5 6 3
1
7 4
5 7 2 4 3 1 6
4
Hint
Explanation for Sample
All possible cases are: 4 7 2 4 5 7 2 4 3 5 7 2 4 3 1 6.
Constraints
For of the testdata, it is guaranteed that , .
Notes
This problem is translated from COCI2007-2008 CONTEST #1 T5 SREDNJI
Translated by ChatGPT 5