CF938E.Max History

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an array a of length n. We define f__a the following way:

  • Initially f__a = 0, M = 1;
  • for every 2 ≤ i ≤ n if a__M < a__i then we set f__a = f__a + a__M and then set M = i.

Calculate the sum of f__a over all n! permutations of the array a modulo 109 + 7.

Note: two elements are considered different if their indices differ, so for every array a there are exactly n! permutations.

给你一个长度为 nn 的数组 aa。我们按如下方式定义 faf_a:

  • 初始时 fa=0f_a = 0,M=1M = 1;
  • 对每个 2≤i≤n2 \le i \le n,若 aM<aia_M < a_i,则令 fa=fa+aMf_a = f_a + a_M,然后令 M=iM = i。

请计算 faf_a 在数组 aa 的所有 n!n! 个排列上的总和,并对 109+710^9 + 7 取模。

注意:若两个元素下标不同,则视为不同元素,因此对任意数组 aa,其恰好有 n!n! 个排列。

输入格式

The first line contains integer n (1 ≤ n ≤  1 000 000) — the size of array a.

Second line contains n integers _a_1, _a_2, ..., a__n (1 ≤  a__i ≤  109).

第一行包含一个整数 nn(1≤n≤1 000 0001 \leq n \leq 1\,000\,000)—— 数组 aa 的大小。

第二行包含 nn 个整数 a1, a2, ..., ana_1,\,a_2,\,...,\,a_n(1≤ai≤1091 \leq a_i \leq 10^9)。

输出格式

Print the only integer, the sum of f__a over all n! permutations of the array a modulo 109 + 7.

输出唯一的整数,即对数组 aa 的所有 n!n! 个排列计算 faf_a 的和,再对 109+710^9 + 7 取模的结果。

输入输出样例

  • 输入#1

    2
    1 3

    输出#1

    1
  • 输入#2

    3
    1 1 2

    输出#2

    4

说明/提示

For the second example all the permutations are:

  • p = [1, 2, 3] : f__a is equal to 1;
  • p = [1, 3, 2] : f__a is equal to 1;
  • p = [2, 1, 3] : f__a is equal to 1;
  • p = [2, 3, 1] : f__a is equal to 1;
  • p = [3, 1, 2] : f__a is equal to 0;
  • p = [3, 2, 1] : f__a is equal to 0.

Where p is the array of the indices of initial array a. The sum of f__a is equal to 4.

第二个例子中,所有排列如下:

  • p = [1, 2, 3] :f__a 等于 1;
  • p = [1, 3, 2] :f__a 等于 1;
  • p = [2, 1, 3] :f__a 等于 1;
  • p = [2, 3, 1] :f__a 等于 1;
  • p = [3, 1, 2] :f__a 等于 0;
  • p = [3, 2, 1] :f__a 等于 0。

其中 p 是初始数组 a 的下标组成的数组。f__a 的总和等于 4。

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

首页