题解:AT_abc353_d [ABC353D] Another Sigma Problem
一道前缀和好题。
话不多说,先推式子:
可以发现,里面两个求和的部分都可以用前缀和维护,这样时间复杂度为
代码如下:
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
int n;
ll a[200006];
ll pre[200006];
ll pre1[200006];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
pre[i] = (pre[i - 1] + a[i]) % mod;
pre1[i] = (pre1[i - 1] + (ll)pow(10, (ll)(log10(a[i])) + 1)) % mod;
}
ll ans = 0;
for (int i = 1; i < n; i++) {
ll t = (pre[n] - pre[i] + mod) % mod;
t = (t + a[i] % mod * ((pre1[n] - pre1[i] + mod) % mod) % mod) % mod;
ans = (ans + t) % mod;
}
cout << ans;
}