QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#7962. 前缀和

统计

题目描述

小兰很喜欢随机数。

TA 首先选定了一个实数 $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$。保证 $1\leq l\leq r\leq n\leq 10^9$,$p$ 的位数不超过 $6$。

输出格式

输出到标准输出。

输出一个实数,表示答案。你需要保证答案的绝对或相对误差不超过 $10^{-6}$。

样例1输入

3 0.5 1 2

样例1输出

1.000000

样例1解释

有 $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$。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.