LINK

f i = ∑ j = 1 i (   f [ j − 1 ] + g j − 1 ∗ s u m ( j , i )   ) f_i=\sum\limits_{j=1}^i (\ f[j-1]+g_{j-1}*sum(j,i)\ ) fi=j=1i( f[j1]+gj1sum(j,i) )

其中 g i g_i gi表示 [ 1 , i ] [1,i] [1,i]的分割方案,可以得到

f i − 1 = ∑ j = 1 i − 2 f j + ∑ j = 1 i − 1 g j − 1 ∗ s u m ( j , i − 1 ) f_{i-1}=\sum\limits_{j=1}^{i-2}f_j+\sum\limits_{j=1}^{i-1} g_{j-1}*sum(j,i-1) fi1=j=1i2fj+j=1i1gj1sum(j,i1)

f i = ∑ j = 1 i − 1 f j + ∑ j = 1 i g j − 1 ∗ s u m ( j , i ) f_{i}=\sum\limits_{j=1}^{i-1} f_j+\sum\limits_{j=1}^ig_{j-1}*sum(j,i) fi=j=1i1fj+j=1igj1sum(j,i)

= ∑ j = 1 i − 1 f j + ∑ j = 1 i − 1 g j − 1 ∗ ( s u m ( j , i − 1 ) ∗ 10 + a i ) + g i − 1 ∗ a i =\sum\limits_{j=1}^{i-1} f_j+\sum\limits_{j=1}^{i-1}g_{j-1}*(sum(j,i-1)*10+a_i)+g_{i-1}*a_i =j=1i1fj+j=1i1gj1(sum(j,i1)10+ai)+gi1ai

= ∑ j = 1 i − 1 f j + 10 ∗ ∑ j = 1 i − 1 g j − 1 ∗ s u m ( j , i − 1 ) + a i ∗ ∑ j = 1 i − 1 g j − 1 + g i − 1 ∗ a i =\sum\limits_{j=1}^{i-1} f_j+10*\sum\limits_{j=1}^{i-1} g_{j-1}*sum(j,i-1)+a_i*\sum\limits_{j=1}^{i-1}g_{j-1}+g_{i-1}*a_i =j=1i1fj+10j=1i1gj1sum(j,i1)+aij=1i1gj1+gi1ai

可以发现,可以分别动态维护这两项

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 1e6+10;
const int mod = 998244353;
int n,f[maxn],g[maxn],pre[maxn];
char a[maxn];
signed main()
{
	cin >> ( a+1 ); n = strlen( a+1 );
	g[0] = g[1] = pre[0] = 1;
	for(int i=2;i<=1000000;i++)	g[i] = g[i-1]*2%mod;
	for(int i=1;i<=1000000;i++)	pre[i] = ( pre[i-1]+g[i] )%mod;
	int sumf = a[1]-'0', sum = a[1]-'0';
	f[1] = sumf;
	for(int i=2;i<=n;i++)
	{
		sum = ( 10*sum )%mod;
		f[i] = ( sumf+sum+( a[i]-'0' )*pre[i-1]%mod )%mod;
		sum = f[i]-sumf;
		sumf = ( sumf+f[i] )%mod;
	}	
	cout << ( f[n]%mod+mod )%mod;
}