#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<iomanip>
using namespace std;
long long a[200005]={0},s[200005]={0};
int main(){
long long n;
cin>>n;
for(int i = 1; i <= n; i++){
cin>>a[i];
s[i] = s[i-1] + a[i];
}
long long s2 = 0;
for(int i = 1; i <= n; i++){
s2 += a[i]*(s[n]-s[i]);
}
cout<<s2;
return 0;
}
【蓝桥杯】省赛:2022求和(简单)——前缀和
最新推荐文章于 2024-04-08 15:16:16 发布