CF1167F.Scalar Queries

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an array a1,a2,…,ana_1, a_2, \dots, a_n. All aia_i are pairwise distinct.

Let's define function f(l,r)f(l, r) as follows:

  • let's define array b1,b2,…,br−l+1b_1, b_2, \dots, b_{r - l + 1}, where bi=al−1+ib_i = a_{l - 1 + i};
  • sort array bb in increasing order;
  • result of the function f(l,r)f(l, r) is ∑i=1r−l+1bi⋅i\sum\limits_{i = 1}^{r - l + 1}{b_i \cdot i}.

Calculate (∑1≤l≤r≤nf(l,r))mod  (109+7)\left(\sum\limits_{1 \le l \le r \le n}{f(l, r)}\right) \mod (10^9+7), i.e. total sum of ff for all subsegments of aa modulo 109+710^9+7.

给你一个数组 a1,a2,…,ana_1, a_2, \dots, a_n,其中所有 aia_i 两两互不相同。

我们定义函数 f(l,r)f(l, r) 如下:

  • 定义数组 b1,b2,…,br−l+1b_1, b_2, \dots, b_{r - l + 1},其中 bi=al−1+ib_i = a_{l - 1 + i};
  • 将数组 bb 按升序排序;
  • 函数 f(l,r)f(l, r) 的结果为 ∑i=1r−l+1bi⋅i\sum\limits_{i = 1}^{r - l + 1}{b_i \cdot i}。

请计算 (∑1≤l≤r≤nf(l,r))mod  (109+7)\left(\sum\limits_{1 \le l \le r \le n}{f(l, r)}\right) \mod (10^9+7),即对数组 aa 的所有连续子段(子数组)计算 f(l,r)f(l, r) 的总和,再对 109+710^9+7 取模。

输入格式

The first line contains one integer nn (1≤n≤5⋅1051 \le n \le 5 \cdot 10^5) — the length of array aa.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1091 \le a_i \le 10^9, ai≠aja_i \neq a_j for i≠ji \neq j) — array aa.

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

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1091 \le a_i \le 10^9,且当 i≠ji \neq j 时 ai≠aja_i \neq a_j)——数组 aa。

输出格式

Print one integer — the total sum of ff for all subsegments of aa modulo 109+710^9+7

输出一个整数——所有子段的 ff 值之和对 109+710^9+7 取模的结果。

输入输出样例

  • 输入#1

    4
    5 2 4 7

    输出#1

    167
  • 输入#2

    3
    123456789 214365879 987654321

    输出#2

    582491518

说明/提示

Description of the first example:

  • f(1,1)=5⋅1=5f(1, 1) = 5 \cdot 1 = 5;
  • f(1,2)=2⋅1+5⋅2=12f(1, 2) = 2 \cdot 1 + 5 \cdot 2 = 12;
  • f(1,3)=2⋅1+4⋅2+5⋅3=25f(1, 3) = 2 \cdot 1 + 4 \cdot 2 + 5 \cdot 3 = 25;
  • f(1,4)=2⋅1+4⋅2+5⋅3+7⋅4=53f(1, 4) = 2 \cdot 1 + 4 \cdot 2 + 5 \cdot 3 + 7 \cdot 4 = 53;
  • f(2,2)=2⋅1=2f(2, 2) = 2 \cdot 1 = 2;
  • f(2,3)=2⋅1+4⋅2=10f(2, 3) = 2 \cdot 1 + 4 \cdot 2 = 10;
  • f(2,4)=2⋅1+4⋅2+7⋅3=31f(2, 4) = 2 \cdot 1 + 4 \cdot 2 + 7 \cdot 3 = 31;
  • f(3,3)=4⋅1=4f(3, 3) = 4 \cdot 1 = 4;
  • f(3,4)=4⋅1+7⋅2=18f(3, 4) = 4 \cdot 1 + 7 \cdot 2 = 18;
  • f(4,4)=7⋅1=7f(4, 4) = 7 \cdot 1 = 7;

第一个示例的说明:

  • f(1,1)=5⋅1=5f(1, 1) = 5 \cdot 1 = 5;
  • f(1,2)=2⋅1+5⋅2=12f(1, 2) = 2 \cdot 1 + 5 \cdot 2 = 12;
  • f(1,3)=2⋅1+4⋅2+5⋅3=25f(1, 3) = 2 \cdot 1 + 4 \cdot 2 + 5 \cdot 3 = 25;
  • f(1,4)=2⋅1+4⋅2+5⋅3+7⋅4=53f(1, 4) = 2 \cdot 1 + 4 \cdot 2 + 5 \cdot 3 + 7 \cdot 4 = 53;
  • f(2,2)=2⋅1=2f(2, 2) = 2 \cdot 1 = 2;
  • f(2,3)=2⋅1+4⋅2=10f(2, 3) = 2 \cdot 1 + 4 \cdot 2 = 10;
  • f(2,4)=2⋅1+4⋅2+7⋅3=31f(2, 4) = 2 \cdot 1 + 4 \cdot 2 + 7 \cdot 3 = 31;
  • f(3,3)=4⋅1=4f(3, 3) = 4 \cdot 1 = 4;
  • f(3,4)=4⋅1+7⋅2=18f(3, 4) = 4 \cdot 1 + 7 \cdot 2 = 18;
  • f(4,4)=7⋅1=7f(4, 4) = 7 \cdot 1 = 7;

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

首页