A14804 | Game on Sum (Hard Version)
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
This is the hard version of the problem. The difference is the constraints on $n$ , $m$ and $t$ . You can make hacks only if all versions of the problem are solved.
Alice and Bob are given the numbers $n$ , $m$ and $k$ , and play a game as follows:
The game has a score that Alice tries to maximize, and Bob tries to minimize. The score is initially $0$ . The game consists of $n$ turns. Each turn, Alice picks a real number from $0$ to $k$ (inclusive) which Bob either adds to or subtracts from the score of the game. But throughout the game, Bob has to choose to add at least $m$ out of the $n$ turns.
Bob gets to know which number Alice picked before deciding whether to add or subtract the number from the score, and Alice gets to know whether Bob added or subtracted the number for the previous turn before picking the number for the current turn (except on the first turn since there was no previous turn).
If Alice and Bob play optimally, what will the final score of the game be?
Alice and Bob are given the numbers $n$ , $m$ and $k$ , and play a game as follows:
The game has a score that Alice tries to maximize, and Bob tries to minimize. The score is initially $0$ . The game consists of $n$ turns. Each turn, Alice picks a real number from $0$ to $k$ (inclusive) which Bob either adds to or subtracts from the score of the game. But throughout the game, Bob has to choose to add at least $m$ out of the $n$ turns.
Bob gets to know which number Alice picked before deciding whether to add or subtract the number from the score, and Alice gets to know whether Bob added or subtracted the number for the previous turn before picking the number for the current turn (except on the first turn since there was no previous turn).
If Alice and Bob play optimally, what will the final score of the game be?
输入格式
The first line of the input contains a single integer $t$ ( $1 \le t \le 10^5$ ) — the number of test cases. The description of test cases follows.
Each test case consists of a single line containing the three integers, $n$ , $m$ , and $k$ ( $1 \le m \le n \le 10^6, 0 \le k < 10^9 + 7$ ) — the number of turns, how many of those turns Bob has to add, and the biggest number Alice can choose, respectively.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$ .
Each test case consists of a single line containing the three integers, $n$ , $m$ , and $k$ ( $1 \le m \le n \le 10^6, 0 \le k < 10^9 + 7$ ) — the number of turns, how many of those turns Bob has to add, and the biggest number Alice can choose, respectively.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$ .
输出格式
For each test case output a single integer number — the score of the optimal game modulo $10^9 + 7$ .
Formally, let $M = 10^9 + 7$ . It can be shown that the answer can be expressed as an irreducible fraction $\frac{p}{q}$ , where $p$ and $q$ are integers and $q \not \equiv 0 \pmod{M}$ . Output the integer equal to $p \cdot q^{-1} \bmod M$ . In other words, output such an integer $x$ that $0 \le x < M$ and $x \cdot q \equiv p \pmod{M}$ .
Formally, let $M = 10^9 + 7$ . It can be shown that the answer can be expressed as an irreducible fraction $\frac{p}{q}$ , where $p$ and $q$ are integers and $q \not \equiv 0 \pmod{M}$ . Output the integer equal to $p \cdot q^{-1} \bmod M$ . In other words, output such an integer $x$ that $0 \le x < M$ and $x \cdot q \equiv p \pmod{M}$ .
输入输出样例
输入 #1
7 3 3 2 2 1 10 6 3 10 6 4 10 100 1 1 4 4 0 69 4 20
输出 #1
6 5 375000012 500000026 958557139 0 49735962
In the first test case, the entire game has $3$ turns, and since $m = 3$ , Bob has to add in each of them. Therefore Alice should pick the biggest number she can, which is $k = 2$ , every turn.
In the third test case, Alice has a strategy to guarantee a score of $\frac{75}{8} \equiv 375000012 \pmod{10^9 + 7}$ .
In the fourth test case, Alice has a strategy to guarantee a score of $\frac{45}{2} \equiv 500000026 \pmod{10^9 + 7}$ .
In the third test case, Alice has a strategy to guarantee a score of $\frac{75}{8} \equiv 375000012 \pmod{10^9 + 7}$ .
In the fourth test case, Alice has a strategy to guarantee a score of $\frac{45}{2} \equiv 500000026 \pmod{10^9 + 7}$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted