QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#21245. 中央値以上

Statistics

Farmer John は $N$ 頭の牛を一列に並べ身長を測ります。$1 \le N \le 100,000$、牛 $i$ の身長は $H_{i}$ ナノメートル、$1 \le H_{i} \le 1,000,000,000$ です。FJ は精密測定を信じています!連続部分列の写真を撮り、郡の祭りの牛写真コンテストに出したいです。

応募写真には奇妙な規則があります。写った牛の身長の中央値が閾値 $X$ 以上の場合のみ応募できます。$1 \le X \le 1,000,000,000$ です。

本問で配列 $A[0...K]$ の中央値は、$A$ をソートした後の $A[\mathrm{ceiling}(K/2)]$ です。$\mathrm{ceiling}(K/2)$ は $K/2$ の切り上げ($K/2$ が整数なら $K/2$ 自体)です。例えば $\{7,3,2,6\}$ は 6、$\{5,4,8\}$ は 5 が中央値です。

応募できる異なる連続部分列の数を求めてください。

入力

  • 1 行目:空白で区切った整数 $N$ と $X$。
  • 2..$N$+1 行目:$i+1$ 行目に整数 $H_{i}$ 一つ。

出力

  • 1 行目:中央値が $X$ 以上の部分列数。32 ビット整数に収まらないかもしれません。

入出力例

入力 1

4 6
10
5
6
2

出力 1

7

注記

四頭の身長は $10,5,6,2$ です。中央値が 6 以上の連続部分列を数えます。

連続部分列は 10 個、そのうち 7 個だけ中央値が 6 以上です:$\{10\}$、$\{6\}$、$\{10,5\}$、$\{5,6\}$、$\{6,2\}$、$\{10,5,6\}$、$\{10,5,6,2\}$。

問題作成者:Brian Dean

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.