CF1817E.Half-sum

NOI/NOI+/CTSC

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You're given a multiset of non-negative integers a1,a2,…,an{a_1, a_2, \dots, a_n}.

In one step you take two elements xx and yy of the multiset, remove them and insert their mean value x+y2\frac{x + y}{2} back into the multiset.

You repeat the step described above until you are left with only two numbers AA and BB. What is the maximum possible value of their absolute difference ∣A−B∣|A-B|?

Since the answer is not an integer number, output it modulo 109+710^9+7.

给你一个非负整数的多重集 {a1,a2,…,an}\{a_1, a_2, \dots, a_n\}。

每一步中,你从该多重集中选取两个元素 xx 和 yy,将它们移除,并将它们的平均值 x+y2\frac{x + y}{2} 重新插入该多重集。

你重复上述操作,直到多重集中仅剩下两个数 AA 和 BB。问:它们的绝对差 ∣A−B∣|A-B| 的最大可能值是多少?

由于答案不一定是整数,请将结果对 109+710^9+7 取模后输出。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1001 \le t \le 100). Description of the test cases follows.

The first line of each test case contains a single integer nn (2≤n≤1062 \le n \le 10^6) — the size of the multiset.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1090 \le a_i \le 10^9) — the elements of the multiset.

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

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

每个测试用例的第一行包含一个整数 nn(2≤n≤1062 \le n \le 10^6)—— 多重集的大小。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤1090 \le a_i \le 10^9)—— 多重集的元素。

保证所有测试用例的 nn 之和不超过 10610^6。

输出格式

For each test case, output a single integer, the answer to the problem modulo 109+710^9+7.

Formally, let M=109+7M = 10^9+7. It can be shown that the answer can be expressed as an irreducible fraction pq\frac{p}{q}, where pp and qq are integers and q≢0(modM)q \not \equiv 0 \pmod{M}. Output the integer equal to p⋅q−1 mod Mp \cdot q^{-1} \bmod M. In other words, output an integer xx such that 0≤x<M0 \le x \lt M and x⋅q≡p(modM)x \cdot q \equiv p \pmod{M}.

对于每个测试用例,输出一个整数,即问题答案对 109+710^9+7 取模的结果。

形式化地,令 M=109+7M = 10^9+7。可以证明答案可表示为既约分数 pq\frac{p}{q},其中 pp 和 qq 为整数,且 q≢0(modM)q \not \equiv 0 \pmod{M}。请输出整数 p⋅q−1 mod Mp \cdot q^{-1} \bmod M。换言之,输出满足 0≤x<M0 \le x < M 且 x⋅q≡p(modM)x \cdot q \equiv p \pmod{M} 的整数 xx。

输入输出样例

  • 输入#1

    5
    2
    7 3
    4
    1 2 10 11
    3
    1 2 3
    6
    64 32 64 16 64 0
    4
    1 1 1 1

    输出#1

    4
    9
    500000005
    59
    0

说明/提示

In the first case, you can't do any operations, so the answer is ∣7−3∣=4|7-3|=4.

In the second case, one of the optimal sequence of operations:

  1. Substitute 11 and 22 with 1.51.5;
  2. Substitute 1010 and 1111 with 10.510.5;
  3. The difference between 1.51.5 and 10.510.5 is 99.

In the third case, the exact answer is 32\frac{3}{2}, and 500 000 005⋅2≡3(mod109+7)500\,000\,005 \cdot 2 \equiv 3 \pmod{10^9+7}.

第一种情况,你无法进行任何操作,因此答案为 ∣7−3∣=4|7-3|=4。

第二种情况,一种最优的操作序列如下:

  1. 将 11 和 22 替换为 1.51.5;
  2. 将 1010 和 1111 替换为 10.510.5;
  3. 1.51.5 与 10.510.5 的差为 99。

第三种情况,精确答案为 32\frac{3}{2},且满足 500 000 005⋅2≡3(mod109+7)500\,000\,005 \cdot 2 \equiv 3 \pmod{10^9+7}。

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

首页