CF2192F.Fish Fight

省选/NOI-

通过率:0%

时间限制:4.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In a pond, nn fish are in a line. For each fish ii, its size is aia_i, and any fish that eats it grows by bib_i.

Alice picks fish xx, Bob picks fish yy. They alternate turns, starting with Alice's fish. On each player's turn, let their fish have size pp. The fish will eat an adjacent fish with size qq that satisfies p≥qp \geq q. If more than one such fish exists, it chooses uniformly at random among them. Eating increases its size by the eaten fish's bib_i.

If, at the start of its turn, a fish cannot eat any adjacent fish, it is instead eaten by its neighbours (A fish at an endpoint has one neighbour; a fish in the interior has two). If Alice's fish is eaten (either by Bob's fish or by her neighboring fishes), she immediately loses. Similarly, if Bob's fish is eaten (either by Alice's fish or by his neighboring fishes), he immediately loses.

Given Alice's and Bob's chosen fishes, compute the probability that Alice wins, modulo 109+710^9+7.

More formally, let M=109+7M=10^9+7. The answer can be written as an irreducible fraction pq\frac{p}{q} with q≢0(modM)q \not\equiv 0 \pmod M. Output p q−1 mod Mp \, q^{-1} \bmod M, the unique integer xx with 0≤x<M0 \le x \lt M and xq≡p(modM)x q \equiv p \pmod M.

一个池塘中有 nn 条鱼排成一行。对于第 ii 条鱼,其大小为 aia_i,且任何吃掉它的鱼的大小将增加 bib_i。

爱丽丝选择第 xx 条鱼,鲍勃选择第 yy 条鱼。他们轮流行动,由爱丽丝的鱼先行开始。在每位玩家的回合中,设其鱼当前大小为 pp。该鱼将吃掉一个相邻的、大小为 qq 且满足 p≥qp \geq q 的鱼。若存在多个满足条件的相邻鱼,则等概率地随机选择其中一个。吃掉一条鱼后,该鱼的大小增加被吃鱼对应的 bib_i 值。

若在某条鱼的回合开始时,它无法吃掉任何相邻的鱼,则它反而会被其邻鱼吃掉(位于行首或行尾的鱼只有一个邻鱼;位于中间的鱼有两个邻鱼)。若爱丽丝的鱼被吃掉(无论是被鲍勃的鱼吃掉,还是被其邻鱼吃掉),她立即失败。类似地,若鲍勃的鱼被吃掉(无论是被爱丽丝的鱼吃掉,还是被其邻鱼吃掉),他立即失败。

给定爱丽丝与鲍勃所选的鱼,计算爱丽丝获胜的概率,结果对 109+710^9+7 取模。

更严格地说,令 M=109+7M = 10^9 + 7。答案可表示为最简分数 pq\frac{p}{q},其中 q≢0(modM)q \not\equiv 0 \pmod{M}。请输出 p q−1 mod Mp \, q^{-1} \bmod M,即唯一满足 0≤x<M0 \le x < M 且 xq≡p(modM)x q \equiv p \pmod{M} 的整数 xx。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤5001 \le t \le 500). The description of the test cases follows.

The first line of each testcase contains a single integer nn (2≤n≤30002 \le n \le 3000) — the number of fish in pond.

The second line contains two integers xx and yy (1≤x,y≤n1 \le x,y \le n; x≠yx \neq y).

The third line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \le a_i \le 10^9).

The fourth line contains nn integers b1,b2,…,bnb_1, b_2, \ldots, b_n (0≤bi≤1090 \le b_i \le 10^9).

It is guaranteed that the sum of nn does not exceed 30003000 over all test cases.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤5001 \le t \le 500)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤30002 \le n \le 3000)—— 表示池塘中鱼的数量。

第二行包含两个整数 xx 和 yy(1≤x,y≤n1 \le x,y \le n;x≠yx \neq y)。

第三行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \le a_i \le 10^9)。

第四行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \ldots, b_n(0≤bi≤1090 \le b_i \le 10^9)。

保证所有测试用例中 nn 的总和不超过 30003000。

输出格式

For each test case output a single integer which is the probability that Alice will win modulo 109+710^9 + 7.

对于每个测试用例,输出一个整数,表示 Alice 获胜的概率对 109+710^9 + 7 取模的结果。

输入输出样例

  • 输入#1

    6
    2
    1 2
    1 2
    1 1
    2
    1 2
    2 1
    1 1
    3
    2 3
    1 4 4
    0 1 1
    5
    4 2
    2 6 5 5 3
    1 2 1 3 2
    7
    3 5
    1 1 1 1 1 1 1
    0 0 0 0 0 0 1
    10
    8 3
    2 5 9 3 8 4 5 6 2 7
    1 3 5 2 7 3 4 2 2 3

    输出#1

    0
    1
    500000004
    750000006
    375000003
    687500005

说明/提示

In the first test case, Alice's fish can't eat any of the adjacent fish, hence Alice always loses.

In the second test case, Alice's fish has only one adjacent fish, which is Bob's fish, Since Alice's fish size is greater than or equal to Bob's fish size, Alice always wins.

In the third test case, in the first turn, Alice's fish can eat both the adjacent fish.

Case 11: It eats fish 33 (Bob's fish). Alice wins.

Case 22: It eats fish 11. The new size of Alice's fish will be a2+b1=4+0=4a_2 + b_1 = 4 + 0 = 4. This will lead to Bob's fish always eating Alice's fish in the second turn. Alice loses.

Both cases are equally likely, hence the probability of Alice winning is 0.50.5

In the fourth test case, the probability of Alice winning is 0.750.75

在第一个测试用例中,Alice 的鱼无法吃掉任何相邻的鱼,因此 Alice 总是输。

在第二个测试用例中,Alice 的鱼仅有一个相邻的鱼,即 Bob 的鱼。由于 Alice 的鱼的尺寸大于或等于 Bob 的鱼的尺寸,Alice 总是赢。

在第三个测试用例中,在第一回合,Alice 的鱼可以吃掉两个相邻的鱼。

情况 11:它吃掉鱼 33(Bob 的鱼)。Alice 获胜。

情况 22:它吃掉鱼 11。Alice 的鱼的新尺寸将为 a2+b1=4+0=4a_2 + b_1 = 4 + 0 = 4。这将导致 Bob 的鱼在第二回合总是吃掉 Alice 的鱼。Alice 输。

两种情况出现的可能性相等,因此 Alice 获胜的概率为 0.50.5。

在第四个测试用例中,Alice 获胜的概率为 0.750.75。

输入解题思路,AI测评打分。不知道怎么写?

首页