QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 512 MB مجموع النقاط: 100

#7962. 前缀和

الإحصائيات

小蘭は乱数が大好きです。

彼女はまず実数 $0 < p < 1$ を選び、次に $n$ 個の乱数 $x_1, \dots, x_n$ を生成しました。各数値は独立に以下の規則に従って生成されます。

  • $x_i$ は確率 $p$ で $1$ となり、確率 $(1-p)p$ で $2$ となり、確率 $(1-p)^2p$ で $3$ となり、以下同様に続きます。

これらの乱数を生成した後、小蘭はその数列の累積和を求め、数列 $y_1, \dots, y_n$ を得ました。

$1 \leq l \leq r \leq n$ が与えられたとき、$y_i$ が $[l, r]$ の範囲内に含まれる個数の期待値を求めてください。

入力

標準入力から以下の形式でデータが与えられます。

一行に $n, p, l, r$ の4つの値が入力されます。$1 \leq l \leq r \leq n \leq 10^9$ であり、$p$ の小数点以下の桁数は $6$ 桁以内であることが保証されます。

出力

標準出力に答えを出力してください。

答えは実数で出力してください。絶対誤差または相対誤差が $10^{-6}$ 以下であれば正解とみなされます。

入出力例

入力 1

3 0.5 1 2

出力 1

1.000000

注記

$1/4$ の確率で $x_1=1$ かつ $x_2>1$ となり、このとき $y_1$ だけが $[1, 2]$ に含まれます。

$1/4$ の確率で $x_1=1$ かつ $x_2=1$ となり、このとき $y_1, y_2$ が $[1, 2]$ に含まれます。

$1/4$ の確率で $x_1=2$ となり、このとき $y_1$ だけが $[1, 2]$ に含まれます。

したがって、期待値は $1/4 \cdot (1 + 2 + 1) = 1$ となります。

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.