Scalar Queries CodeForces - 1167F (计数,树状数组)

You are given an array $a_1,a_2,…,a_n$. All aiai are pairwise distinct.

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

  • let's define array $b_1,b_2,…,b_{r-l+1}$, where $b_i=a_{l-1+i}$;
  • sort array bb in increasing order;
  • result of the function $f(l,r)$ is $\sum\limits_{i=1}^{r-l+1}b_i\cdot i$.

Calculate $\Bigg(\sum\limits_{1\le l\le r\le n}f(l,r)\Bigg )mod(10^9+7)$, i.e. total sum of $f$ for all subsegments of $a$ modulo $10^9+7$.

可以得到$a_x$的贡献为

$\sum\limits_{\substack{a_i<a_x\\ i<x}} i\cdot (n-x+1)+\sum\limits_{\substack{a_i<a_x\\ i>x}}x\cdot (n-i+1)+x\cdot (n-x+1)$

猜你喜欢

转载自www.cnblogs.com/uid001/p/10882397.html