1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
| #define _CRT_SECURE_NO_WARNINGS #pragma GCC optimize(3) #include <iostream> #include <algorithm> #include <utility> #include <vector> #include <istream> #include <map> #include <cmath> #include <stack> #include <set> #include <queue> #include <cstring> #include <string> #include <fstream> #define ll long long #define maxn 1000005 #define mdl 998244353 #define clr(a,n) for(int i=0;i<n;i++)a[i]=0 #define cfast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define pll pair<ll,ll> #define pii pair<int,int> #define inc(i,a,n) for(int i=a;i<n;i++) #define vset(a,n,m) for(int i=0;i<n;i++)a[i]=m; #define endl '\n' #define PI 3.14159265358979 using namespace std; ll gcd(ll a, ll b) { if (a < b)swap(a, b); if (b == 0)return a; return gcd(b, a % b); } ll cpow(ll x, ll n) { ll ans = 1; while (n > 0) { if (n & 1) ans = (ans * x) % mdl; x = (x * x) % mdl; n >>= 1; } return ans; } ll getpos(int p, ll n) { return n / cpow(10, p - 1) % 10; } ll getwei(ll n) { int res = 0; while (n) { res++; n /= 10; } return res; }
int a[maxn]; int pre[maxn][62]; int dp[62][62][3]; char str[1000002]; inline void add(int& x, int y) { x = (x + y < mdl ? x + y : x + y - mdl); } int main() {
int t=1;
while (t--) { int ans = 0; scanf("%s", str); int len = strlen(str); inc(i, 1, len+1) { if (str[i-1] >= '0' && str[i-1] <= '9')a[i] = str[i-1] - '0'; else if (str[i-1] >= 'a' && str[i-1] <= 'z')a[i] = 10 + str[i-1] - 'a'; else a[i] = 36 + str[i-1] - 'A'; inc(j, 0, 62) { pre[i][j] = pre[i - 1][j]; } pre[i][a[i]]++; } for (int i = len; i >= 3; i--) { int m = a[i]; inc(j, 0, 62) { if (m == j)continue; add(dp[m][j][0], dp[j][m][1]); add(dp[m][j][1], dp[j][m][2]); add(dp[m][j][2], pre[len][j] - pre[i][j]); } int tmp = (1ll*(i - 1) * (i - 2) / 2) % mdl; inc(j, 0, 62) { add(tmp,mdl - (1ll * pre[i - 1][j] * (pre[i - 1][j] - 1) / 2) % mdl); } inc(j, 0, 62) { int minu = (1ll * (pre[i - 1][j]) * (i - 1 - pre[i - 1][j]) % mdl + 1ll * (pre[i - 1][m]) * (i-1 - pre[i - 1][m]) % mdl)%mdl; int tt = tmp; add(tt, mdl - minu); add(tt, 1ll * pre[i - 1][m] * pre[i - 1][j] % mdl); add(ans, 1ll * tt * dp[m][j][0] % mdl); dp[m][j][0] = 0; } } printf("%d\n", ans); } return 0; }
|