CF1167F.Scalar Queries
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a1,a2,…,an. All ai are pairwise distinct.
Let's define function f(l,r) as follows:
- let's define array b1,b2,…,br−l+1, where bi=al−1+i;
- sort array b in increasing order;
- result of the function f(l,r) is i=1∑r−l+1bi⋅i.
Calculate (1≤l≤r≤n∑f(l,r))mod(109+7), i.e. total sum of f for all subsegments of a modulo 109+7.
给你一个数组 a1,a2,…,an,其中所有 ai 两两互不相同。
我们定义函数 f(l,r) 如下:
- 定义数组 b1,b2,…,br−l+1,其中 bi=al−1+i;
- 将数组 b 按升序排序;
- 函数 f(l,r) 的结果为 i=1∑r−l+1bi⋅i。
请计算 (1≤l≤r≤n∑f(l,r))mod(109+7),即对数组 a 的所有连续子段(子数组)计算 f(l,r) 的总和,再对 109+7 取模。
输入格式
The first line contains one integer n (1≤n≤5⋅105) — the length of array a.
The second line contains n integers a1,a2,…,an (1≤ai≤109, ai=aj for i=j) — array a.
第一行包含一个整数 n(1≤n≤5⋅105)——数组 a 的长度。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109,且当 i=j 时 ai=aj)——数组 a。
输出格式
Print one integer — the total sum of f for all subsegments of a modulo 109+7
输出一个整数——所有子段的 f 值之和对 109+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=5;
- f(1,2)=2⋅1+5⋅2=12;
- f(1,3)=2⋅1+4⋅2+5⋅3=25;
- f(1,4)=2⋅1+4⋅2+5⋅3+7⋅4=53;
- f(2,2)=2⋅1=2;
- f(2,3)=2⋅1+4⋅2=10;
- f(2,4)=2⋅1+4⋅2+7⋅3=31;
- f(3,3)=4⋅1=4;
- f(3,4)=4⋅1+7⋅2=18;
- f(4,4)=7⋅1=7;
第一个示例的说明:
- f(1,1)=5⋅1=5;
- f(1,2)=2⋅1+5⋅2=12;
- f(1,3)=2⋅1+4⋅2+5⋅3=25;
- f(1,4)=2⋅1+4⋅2+5⋅3+7⋅4=53;
- f(2,2)=2⋅1=2;
- f(2,3)=2⋅1+4⋅2=10;
- f(2,4)=2⋅1+4⋅2+7⋅3=31;
- f(3,3)=4⋅1=4;
- f(3,4)=4⋅1+7⋅2=18;
- f(4,4)=7⋅1=7;
输入解题思路,AI测评打分。不知道怎么写?