CF1612G.Max Sum Array

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an array c=[c1,c2,…,cm]c = [c_1, c_2, \dots, c_m]. An array a=[a1,a2,…,an]a = [a_1, a_2, \dots, a_n] is constructed in such a way that it consists of integers 1,2,…,m1, 2, \dots, m, and for each i∈[1,m]i \in [1,m], there are exactly cic_i occurrences of integer ii in aa. So, the number of elements in aa is exactly ∑i=1mci\sum\limits_{i=1}^{m} c_i.

Let's define for such array aa the value f(a)f(a) as $$f(a) = \sum_{\substack{1 \le i \lt j \le n\\ a_i = a_j}}{j - i}.$$

In other words, f(a)f(a) is the total sum of distances between all pairs of equal elements.

Your task is to calculate the maximum possible value of f(a)f(a) and the number of arrays yielding the maximum possible value of f(a)f(a). Two arrays are considered different, if elements at some position differ.

给你一个数组 c=[c1,c2,…,cm]c = [c_1, c_2, \dots, c_m]。按如下方式构造数组 a=[a1,a2,…,an]a = [a_1, a_2, \dots, a_n]:它由整数 1,2,…,m1, 2, \dots, m 组成,且对每个 i∈[1,m]i \in [1,m],整数 ii 在 aa 中恰好出现 cic_i 次。因此,aa 的元素个数恰好为 ∑i=1mci\sum\limits_{i=1}^{m} c_i。

我们定义该数组 aa 的值 f(a)f(a) 为

f(a)=∑_1≤i<j≤na_i=a_jj−i.f(a) = \sum\_{\substack{1 \le i < j \le n\\ a\_i = a\_j}}{j - i}.

换言之,f(a)f(a) 是所有相等元素对之间距离的总和。

你的任务是计算 f(a)f(a) 可能取得的最大值,以及能达到该最大值的数组 aa 的个数。若两个数组在某个位置上的元素不同,则认为它们是不同的数组。

输入格式

The first line contains a single integer mm (1≤m≤5⋅1051 \le m \le 5 \cdot 10^5) — the size of the array cc.

The second line contains mm integers c1,c2,…,cmc_1, c_2, \dots, c_m (1≤ci≤1061 \le c_i \le 10^6) — the array cc.

第一行包含一个整数 mm(1≤m≤5⋅1051 \le m \le 5 \cdot 10^5)—— 数组 cc 的长度。

第二行包含 mm 个整数 c1,c2,…,cmc_1, c_2, \dots, c_m(1≤ci≤1061 \le c_i \le 10^6)—— 数组 cc。

输出格式

Print two integers — the maximum possible value of f(a)f(a) and the number of arrays aa with such value. Since both answers may be too large, print them modulo 109+710^9 + 7.

输出两个整数——f(a)f(a) 的最大可能值,以及达到该最大值的数组 aa 的个数。由于这两个答案可能过大,请对 109+710^9 + 7 取模后输出。

输入输出样例

  • 输入#1

    6
    1 1 1 1 1 1

    输出#1

    0 720
  • 输入#2

    1
    1000000

    输出#2

    499833345 1
  • 输入#3

    7
    123 451 234 512 345 123 451

    输出#3

    339854850 882811119

说明/提示

In the first example, all possible arrays aa are permutations of [1,2,3,4,5,6][1, 2, 3, 4, 5, 6]. Since each array aa will have f(a)=0f(a) = 0, so maximum value is f(a)=0f(a) = 0 and there are 6!=7206! = 720 such arrays.

In the second example, the only possible array consists of 10610^6 ones and its f(a)=∑1≤i<j≤106j−i=166 666 666 666 500 000f(a) = \sum\limits_{1 \le i \lt j \le 10^6}{j - i} = 166\,666\,666\,666\,500\,000 and 166 666 666 666 500 000 mod 109+7=499 833 345166\,666\,666\,666\,500\,000 \bmod{10^9 + 7} = 499\,833\,345.

在第一个例子中,所有可能的数组 aa 都是 [1,2,3,4,5,6][1, 2, 3, 4, 5, 6] 的排列。由于每个数组 aa 均满足 f(a)=0f(a) = 0,因此 f(a)f(a) 的最大值为 00,且这样的数组共有 6!=7206! = 720 个。

在第二个例子中,唯一可能的数组由 10610^6 个 11 组成,其 f(a)=∑1≤i<j≤106j−i=166 666 666 666 500 000f(a) = \sum\limits_{1 \le i \lt j \le 10^6}{j - i} = 166\,666\,666\,666\,500\,000,且 166 666 666 666 500 000 mod 109+7=499 833 345166\,666\,666\,666\,500\,000 \bmod{10^9 + 7} = 499\,833\,345。

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

首页