A15817 | Survival of the Weakest (hard version)
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
This is the hard version of the problem. It differs from the easy one only in constraints on $n$ . You can make hacks only if you lock both versions.
Let $a_1, a_2, \ldots, a_n$ be an array of non-negative integers. Let $F(a_1, a_2, \ldots, a_n)$ be the sorted in the non-decreasing order array of $n - 1$ smallest numbers of the form $a_i + a_j$ , where $1 \le i < j \le n$ . In other words, $F(a_1, a_2, \ldots, a_n)$ is the sorted in the non-decreasing order array of $n - 1$ smallest sums of all possible pairs of elements of the array $a_1, a_2, \ldots, a_n$ . For example, $F(1, 2, 5, 7) = [1 + 2, 1 + 5, 2 + 5] = [3, 6, 7]$ .
You are given an array of non-negative integers $a_1, a_2, \ldots, a_n$ . Determine the single element of the array $\underbrace{F(F(F\ldots F}_{n-1}(a_1, a_2, \ldots, a_n)\ldots))$ . Since the answer can be quite large, output it modulo $10^9+7$ .
Let $a_1, a_2, \ldots, a_n$ be an array of non-negative integers. Let $F(a_1, a_2, \ldots, a_n)$ be the sorted in the non-decreasing order array of $n - 1$ smallest numbers of the form $a_i + a_j$ , where $1 \le i < j \le n$ . In other words, $F(a_1, a_2, \ldots, a_n)$ is the sorted in the non-decreasing order array of $n - 1$ smallest sums of all possible pairs of elements of the array $a_1, a_2, \ldots, a_n$ . For example, $F(1, 2, 5, 7) = [1 + 2, 1 + 5, 2 + 5] = [3, 6, 7]$ .
You are given an array of non-negative integers $a_1, a_2, \ldots, a_n$ . Determine the single element of the array $\underbrace{F(F(F\ldots F}_{n-1}(a_1, a_2, \ldots, a_n)\ldots))$ . Since the answer can be quite large, output it modulo $10^9+7$ .
输入格式
The first line contains one integer $n$ ( $2 \le n \le 2 \cdot 10^5$ ) — the initial length of the array.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $0 \le a_i \le 10^9$ ) — the array elements.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $0 \le a_i \le 10^9$ ) — the array elements.
输出格式
Output a single number — the answer modulo $10^9 + 7$ .
输入输出样例
输入 #1
5 1 2 4 5 6
输出 #1
34
输入 #2
9 1 1 1 7 7 7 9 9 9
输出 #2
256
输入 #3
7 1 7 9 2 0 0 9
输出 #3
20
输入 #4
3 1000000000 1000000000 777
输出 #4
1540
In the first test, the array is transformed as follows: $[1, 2, 4, 5, 6] \to [3, 5, 6, 6] \to [8, 9, 9] \to [17, 17] \to [34]$ . The only element of the final array is $34$ .
In the second test, $F(a_1, a_2, \ldots, a_n)$ is $[2, 2, 2, 8, 8, 8, 8, 8]$ . This array is made up of $3$ numbers of the form $1 + 1$ and $5$ numbers of the form $1 + 7$ .
In the fourth test, the array is transformed as follows: $[10^9, 10^9, 777] \to [10^9+777, 10^9+777] \to [2 \cdot 10^9 + 1554]$ . $2 \cdot 10^9 + 1554$ modulo $10^9+7$ equals $1540$ .
In the second test, $F(a_1, a_2, \ldots, a_n)$ is $[2, 2, 2, 8, 8, 8, 8, 8]$ . This array is made up of $3$ numbers of the form $1 + 1$ and $5$ numbers of the form $1 + 7$ .
In the fourth test, the array is transformed as follows: $[10^9, 10^9, 777] \to [10^9+777, 10^9+777] \to [2 \cdot 10^9 + 1554]$ . $2 \cdot 10^9 + 1554$ modulo $10^9+7$ equals $1540$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted