CF1167F.Scalar Queries
普及/提高-
通过率:0%
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 .
输入格式
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 .
输出格式
Print one integer — the total sum of f for all subsegments of a modulo 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 ;