P30050 [洛谷] Ryoku Loves Learning
提高+
题目描述

Problem Background

Ryoku has inherited Riri's talent in learning, so she is very passionate about studying. However, no matter how much she loves learning, Ryoku can still get tired.

Problem Description

At each moment $i$, Ryoku learns about a new piece of knowledge $i$ with an actual value of $w_i$. Due to her love for learning, she will not choose to ignore this knowledge, but she only has a probability of $p_i$ to successfully grasp it.

However, if Ryoku masters too many pieces of knowledge at once, due to factors such as mental fatigue, her level of affection for the knowledge changes. We describe this affection level with a value $R$. Specifically, let $R = f(l, r)$ represent the total affection level Ryoku has for the knowledge she continuously masters from moment $l$ to moment $r$, with parameters $a, b$ ($0 < a, b < 1$), then:

$$ f(l,r) = a^{b(r-l)} \sum_{i=l}^r w_i $$

Ryoku wants to know the expected sum of the affection levels for each continuous segment of knowledge she masters (note that these segments cannot be contained within a longer segment). Can you help her?

Input Format

The input contains three lines.
The first line contains an integer $n$ and two real numbers $a, b$.
The second line contains $n$ integers, which are $w_i$.
The third line contains $n$ real numbers, which are $p_i$.

Output Format

The output contains one line with a positive real number, which is the answer.

Sample Input and Output

Input Sample #1

3 0.5 0.5
2 3 3
0.5 0.5 0.5

Output Sample #1

3.097

Input Sample #2

6 0.8 0.2
1 1 4 5 1 4
0.9 0.6 0.7 0.7 0.6 0.8

Output Sample #2

10.521

Notes

[Sample 1 Explanation]

When mastering knowledge $1$, $2$, and $3$, the sum of the affection levels for each continuous segment is $\left(\dfrac{1}{2}\right)^{\frac{1}{2} \times 2}(2+3+3) = 4$.

When mastering knowledge $1$ and $2$, the sum of the affection levels for each continuous segment is $\left(\dfrac{1}{2}\right)^{\frac{1}{2} \times 1}(2+3) = \dfrac{5\sqrt{2}}{2} \approx 3.536$.

When mastering knowledge $1$ and $3$, the sum of the affection levels for each continuous segment is $\left(\dfrac{1}{2}\right)^{\frac{1}{2} \times 0} \times 2 + \left(\dfrac{1}{2}\right)^{\frac{1}{2} \times 0} \times 3 = 5$.

When mastering knowledge $2$ and $3$, the sum of the affection levels for each continuous segment is $\left(\dfrac{1}{2}\right)^{\frac{1}{2} \times 1}(3+3) = 3\sqrt{2} \approx 4.243$.

When mastering only knowledge $1$, the sum of the affection levels for each continuous segment is $\left(\dfrac{1}{2}\right)^{\frac{1}{2} \times 0} \times 2 = 2$.

When mastering only knowledge $2$, the sum of the affection levels for each continuous segment is $\left(\dfrac{1}{2}\right)^{\frac{1}{2} \times 0} \times 3 = 3$.

When mastering only knowledge $3$, the sum of the affection levels for each continuous segment is $\left(\dfrac{1}{2}\right)^{\frac{1}{2} \times 0} \times 3 = 3$.

When mastering nothing, the sum of the affection levels for each continuous segment is $0$.

Each of these 8 cases occurs with a probability of $\dfrac{1}{8}$, so the answer is approximately:

$$(4 + 3.536 + 5 + 4.243 + 2 + 3 + 3 + 0) \times \dfrac{1}{8} \approx 3.0973$$


[Data Range and Constraints]

For $20\%$ of the data, $n \le 18$.
For another $15\%$ of the data, $w_i = 1$.
For $55\%$ of the data, $n \le 10^3$.
For another $15\%$ of the data, $w_i = 1$.
For another $15\%$ of the data, $b_i \le 0.2$.

Additionally, for $100\%$ of the data, $0 < n \le 10^5$, $0 < a, b, p_i < 1$, $0 < w_i \le 10^3$. The precision of the input data does not exceed $10^{-2}$.

This problem uses a Special Judge. If your answer is within $10^{-3}$ of the standard answer for any test case, you will pass that test case.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 0.5 0.5 2 3 3 0.5 0.5 0.5
样例输出
3.097