AtCoder Beginner Contest 233 E - Σ[k=0..10^100]floor(X/10^k)
\[1 \ 2 \ 2 \ 5 \\
\ \ 1 \ 2 \ 2 \\
\ \ \ \ 1 \ 2 \\
\ \ \ \ \ \ 1 \\
\]
观察发现每一位只需要维护后缀和
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 5e5 + 10;
int n;
LL sum[N];
char s[N];
int main() {
scanf("%s", s + 1);
n = strlen(s + 1);
vector<int> c;
LL tot = 0;
for (int i = 1; i <= n; i ++ ) sum[i] = sum[i - 1] + s[i] - '0';
reverse(sum + 1, sum + 1 + n);
for (int i = 1; i <= n; i ++ ) {
tot += sum[i];
c.push_back(tot % 10);
tot /= 10;
}
while (tot) {
c.push_back(tot % 10);
tot /= 10;
}
reverse(c.begin(), c.end());
for (auto x : c)
printf("%d", x);
printf("\n");
return 0;
}