題目描述
1267年,戰爭的味道在空氣中瀰漫,強大的尼弗迦德帝國蓄勢待發。覬覦着雅魯加河對岸的北方領域。萊里亞的女王米薇爲了抵禦尼弗迦德帝國的進攻,在萊里亞王國內建造了 n 個城市。第 i個城市中居住着 w_i個公民。當尼弗迦德帝國進攻某一個城市時,其他所有城市將支援被進攻的城市。但這些城市的居民會因爲支援其他城市而產生不滿意度。
當城市 a 要前往城市 b 支援時,會產生 (w_a-w_b)^2點不滿意度。
米薇女王想知道對於每個城市被進攻時,分別會產生多少點不滿意度。
即對於每個城市 xx ,你需要回答 \sum_{i=1}n{(w_i-w_x)2} 的值。
輸入描述
第 1行一個整數 n ,代表有 n 座城市。
第 2 行 n 個整數,第 i 個整數 w_i代表第 i 個城市的人口數量。
2≤n≤10^5
1≤w_i≤10^6
輸出描述
一行 n 個整數,分別是第 1 個被攻擊產生的不滿意度到第 n 個城市被攻擊的不滿意度。
樣例輸入 1
3
3 3 3
樣例輸出 1
0 0 0
樣例輸入 2
3
3 4 5
樣例輸出 2
5 2 5
樣例輸入 3
5
19 4326 7891 744 999
樣例輸出 3
82004658 55159127 173256882 64500983 59594018
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
Scanner read = new Scanner(System.in);
int n = read.nextInt();
long human[] = new long[n];//int會爆
long allsum=0;
long allsquaredsum=0;
for(int i=0;i<n;i++)
{
human[i] = read.nextLong();
allsum+=human[i];
allsquaredsum+=human[i]*human[i];
}
for(int i=0;i<n;i++)
{
if(i!=n-1)
System.out.print(allsquaredsum+n*human[i]*human[i]-2*human[i]*allsum+" ");
else
System.out.print(allsquaredsum+n*human[i]*human[i]-2*human[i]*allsum);
}
}
}