1303: [CQOI2009] Median Graph
Time Limit: 1 Sec Memory Limit: 162 MB[Submit][Status][Discuss]
Description
Given a permutation from 1 to n, count how many consecutive subsequences of odd lengths in the permutation have a median of b. The median is the number in the middle after arranging all elements from small to large.
Input
The first row is two positive integers n and b, and the second row is a permutation of 1~n.
Output
Output an integer, the number of consecutive subsequences with median b.
Sample Input
7 4
5 7 2 4 3 1 6
5 7 2 4 3 1 6
Sample Output
4
HINT
The third example explanation: {4}, {7,2,4}, {5,7,2,4,3} and {5,7,2,4,3,1,6}
N<=100000
Source
Because it is an arrangement of n, b will only appear once, b is recorded as 0, smaller than b is recorded as -1, larger than b is recorded as 1, and the number of sequences with a sum of 0 is calculated.