有n个数,分别为a 1 _1 1, a 2 _2 2, a 3 _3 3, a 4 _4 4, …, a n _n n
a n s ( x , y ) = <munderover> i = x y 1 </munderover> <munderover> j = i + 1 y </munderover> a i a j ans(x, y) = \sum_{i = x}^{y -1}{\sum_{j = i + 1}^{y}{a_i * a_j}} ans(x,y)=i=xy1j=i+1yaiaj
s u m ( x ) = <munderover> i = 1 x </munderover> a i sum(x) = \sum_{i = 1}^{x}{a_i } sum(x)=i=1xai
c o s t ( y ) = a n s ( 1 , y ) = <munderover> i = 1 y 1 </munderover> <munderover> j = i + 1 y </munderover> a i a j cost(y) = ans(1, y)=\sum_{i = 1}^{y -1}{\sum_{j = i + 1}^{y}{a_i * a_j}} cost(y)=ans(1,y)=i=1y1j=i+1yaiaj
: a n s ( x , y ) = c o s t [ y ] c o s t [ x 1 ] s u m [ x 1 ] ( s u m [ y ] s u m [ x 1 ] ) ) 结论:ans(x, y) =cost[y]-cost[x - 1]-sum[x - 1]*(sum[y]-sum[x - 1])) :ans(x,y)=cost[y]cost[x1]sum[x1](sum[y]sum[x1]))

for(int i = 1; i <= n; i++){
	scanf("%lld", &val[i]);
   	sum[i] = sum[i - 1] + val[i];
  }
for(int i = 1; i <= n; i++){
   	for(int j = i + 1; j <= n; j++){
   		 cost[j] += val[i] * val[j];
  	 }
}
for(int i = 1; i <= n; i++){
        cost[i] += cost[i - 1];
 }