QOJ.ac

QOJ

Limite de temps : 1.0 s Limite de mémoire : 32 MB Points totaux : 70

#17100. 中位数

Statistiques

考虑一个由 $N$ 个整数组成的序列 $A$,其中包含 $1$ 到 $N$ 之间的整数。每个整数在序列中恰好出现一次。

$A$ 的连续子序列是指通过从 $A$ 的开头删除若干个(可以不删)数,再从 $A$ 的末尾删除若干个(可以不删)数所得到的序列。

计算 $A$ 有多少个长度为奇数的连续子序列,其中位数等于 $B$。一个序列的中位数是指将该序列升序排序后处于中间位置的元素。例如,序列 $\{5, 1, 3\}$ 的中位数是 $3$。

输入格式

第一行包含两个整数 $N$($1 \le N \le 100\,000$)和 $B$($1 \le B \le N$)。

第二行包含 $N$ 个由空格隔开的整数,表示序列 $A$ 的元素。

输出格式

输出 $A$ 中中位数为 $B$ 的连续子序列的数量。

样例

输入 1

5 4
1 2 3 4 5

输出 1

2

输入 2

6 3
1 2 4 5 6 3

输出 2

1

输入 3

7 4
5 7 2 4 3 1 6

输出 3

4

说明

在第三个样例中,中位数为 $4$ 的四个连续子序列分别是 $\{4\}$、$\{7, 2, 4\}$、$\{5, 7, 2, 4, 3\}$ 和 $\{5, 7, 2, 4, 3, 1, 6\}$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.