3566 中位数


Submit solution

Points: 10
Time limit: 2.0s
Memory limit: 256K

Problem types
Allowed languages
C, C++, Java, Python

描述

给出1~n的一个排列,统计该排列有多少个长度为奇数的连续子序列的中位数是b。中位数是指把所有元素从小到大排列后,位于中间的数。

输入格式

第一行为两个正整数n和b ,第二行为1~n 的排列。

输出格式

输出一个整数,即中位数为b的连续子序列个数。

样例输入

Input 1:
5 4
1 2 3 4 5

Input 2:
6 3
1 2 4 5 6 3

Input 3:
7 4
5 7 2 4 3 1 6

样例输出

Output 1:
2

Output 2:
1

Output 3:
4

限制

各个测试点1s

提示

第三个样例解释:{4}, {7,2,4}, {5,7,2,4,3}和{5,7,2,4,3,1,6}。

对于40%的数据,n<=300;
对于80%的数据,n<=25000;
对于全部的数据,n<=100000。

来源

NOI2009重庆市代表队选拔赛第一题


Comments

There are no comments at the moment.