#P7491. 「Stoi2031」蒲公英的约定(vol.2)
「Stoi2031」蒲公英的约定(vol.2)
Description
Qinghe is playing a game. They have bunches of dandelions, and the -th bunch has flowers.
These dandelions have a magical property: for a given constant , for flowers, flowers are split off as one group, and the remaining flowers continue to be split in the same way, until the split-off group contains no dandelions, i.e. . They call this phenomenon "renxing" (stubbornness).
Now each bunch of dandelions has this "renxing" property. The rules are as follows:
Starting from Qing, the two players take turns to make a travel move. One travel move means choosing one bunch of dandelions and blowing away some flowers from the first group of that bunch. You must blow away at least one flower, and at most the size of the first group; that is, you cannot blow away any dandelions outside the first group.
When the first group becomes empty, the next group becomes the first group. If a bunch has only one group of dandelions left, then this bunch can no longer be chosen. When no bunch can be chosen, the game ends, and the player whose turn it is loses.
They want to know: if, on Qing’s first travel, she chooses uniformly at random one bunch of dandelions that can be operated on, and then uniformly at random chooses the number of flowers to blow away, and after that both players play optimally, what is the value of Qing’s winning probability ?
The difference from vol.1 is that after a bunch of dandelions is partially blown away, it will be regrouped.
Input Format
The first line contains two positive integers , where denotes the Subtask number.
The second line contains positive integers; the -th one is .
If , the third line contains two positive integers , meaning .
Output Format
Output one integer per line, representing Qing’s winning probability .
4 3
1 1 1
1 6
0
6 3
1 7 3
1 3
15143112127689
Hint
Brief statement:
There are bunches of dandelions; the -th bunch has flowers. Given a real number , two players move alternately. Each move can choose one bunch of dandelions, and choose an integer , then blow away flowers from that bunch, where is the number of flowers in that bunch before the move. You must blow away at least one flower. If a player cannot move, that player loses.
Find the value of the first player’s winning probability , under the process where on the first move the first player uniformly at random chooses any operable bunch of dandelions and then uniformly at random chooses the number of flowers to blow away, and afterwards both players use optimal strategies.
Sample explanation:
For sample , Qing cannot make any move, so the winning probability is .
For sample , Qing can choose the -nd bunch and, among two possible moves, choose to blow away flowers to become ; or choose the -rd bunch and choose the only possible move to become . The -st bunch cannot be chosen. The overall winning probability is .
Constraints:
This problem uses bundled testdata. The score and limits of each Subtask are as follows.
| Subtask No. | restriction | Score | ||
|---|---|---|---|---|
| None | ||||
| None | ||||
For of the data, $1 \le n \le 3 \times 10^5, 1 \le s_i \le 10^{10}, 1 \le p<q \le 10^9$.
The input size of this problem is large. You may use the fast input template from the contest statement to speed up reading.
Translated by ChatGPT 5
京公网安备 11011102002149号