思路
code
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 3e5;
const ll mod = 998244353;
ll n, m, a[N];
int main ()
{
cin >> n;
for(ll i = 1; i <= n; i++)
cin >> a[i];
sort(a+1, a+n+1);
ll ans = 0, temp = 0;
for(ll i = 1; i <= n; i++)
{
ans = (ans + a[i]*a[i]) % mod;
ans = (ans + a[i] * temp) % mod;
temp = (2 * temp + a[i]) % mod;
}
cout << ans%mod << endl;
return 0;
}
本文介绍了一段C++代码,用于计算给定数组中元素的平方和,并对结果取模。通过排序数组和使用滚动数组技巧简化计算过程。适合学习者理解数组操作和优化算法。

被折叠的 条评论
为什么被折叠?



