UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#213828#2411. 三元组KXG802048ms4736kbC++112.9kb2024-11-13 21:02:022024-11-13 23:07:22

answer

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int mod = 998244353;
int t, n, maxl[1000010];
long long ld[1000010], ldd[1000010];
long long rd[1000010], rdd[1000010];
char s[1000010], ns[2000010];
void manachar() {
    maxl[1] = 0;
    int maxr = 0, maxi = 0;
    for (int i = 1; i <= 2 * n - 1; i++) {
        if (maxr > i) {
            maxl[i] = min(maxl[2 * maxi - i], maxr - i);
        } else {
            maxl[i] = 0;
        }
        while (ns[i - maxl[i] - 1] == ns[i + maxl[i] + 1]) {
            maxl[i]++;
        }
        if (i + maxl[i] > maxr) {
            maxr = i + maxl[i];
            maxi = i;
        }
    }
}
void addl(int l, int r, int first) {
    // printf("%d ~ %d add l %d down\n", l, r, first);
    ld[l] += first;
    ld[r + 1] -= first;
    ldd[l + 1]--;
    ldd[r + 1]++;
    ld[r + 1] += r - l;
}
void addr(int l, int r, int first) {
    // printf("%d ~ %d add r %d down\n", l, r, first);
    rd[l] += first;
    rd[r + 1] -= first;
    rdd[l + 1]--;
    rdd[r + 1]++;
    rd[r + 1] += r - l;
}
int main() {
    scanf("%d", &t);
    while (t--) {
        scanf("%s", s + 1);
        n = strlen(s + 1);
        ns[0] = '?';
        for (int i = 1; i <= n; i++) {
            ld[i] = ldd[i] = rd[i] = rdd[i] = 0;
            ns[2 * i - 1] = s[i];
            ns[2 * i] = '#';
        }
        ns[2 * n] = '$';
        manachar();
        for (int pos = 1; pos <= 2 * n - 1; pos++) {
            if (pos % 2 == 1) {
                int i = (pos + 1) / 2;
                int l = maxl[pos] / 2;
                // printf("%d : %d %d\n", pos, i, l);
                addl(i, i + l, i);
                addr(i - l, i, i + l);
            } else {
                int i1 = pos / 2;
                int i2 = i1 + 1;
                int l = (maxl[pos] + 1) / 2;
                // printf("%d : %d %d %d\n", pos, i1, i2, l);
                addl(i2, i2 + l - 1, i1);
                addr(i1 - l + 1, i1, i2 + l - 1);
            }
            for (int i = 1; i <= n; i++) {
                // printf("r %d : %d %d\n", i, rd[i], rdd[i]);
            }
        }
        // for (int i = 1; i <= n; i++) {
        //     printf("r %d : %d %d\n", i, rd[i], rdd[i]);
        // }
        for (int i = 1; i <= n; i++) {
            ldd[i] += ldd[i - 1];
            rdd[i] += rdd[i - 1];
            ldd[i] %= mod;
            rdd[i] %= mod;
        }
        for (int i = 1; i <= n; i++) {
            ld[i] += ldd[i];
            rd[i] += rdd[i];
            ld[i] += ld[i - 1];
            rd[i] += rd[i - 1];
            ld[i] %= mod;
            rd[i] %= mod;
            // printf("%d : %lld %lld\n", i, ld[i], rd[i]);
        }
        long long ans = 0;
        for (int i = 1; i < n; i++) {
            ans += ld[i] * rd[i + 1] % mod;
        }
        printf("%lld\n", ans % mod);
    }
    return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 544kb

input:

10
kyynjrttqngurtcvcjnnuqmstrntnpghrqqqp
lqfnqzykyzzynqnqyywzzwwfnyzlwykznyfhyknfnk
fuhjuhhuhuqjuuqu...

output:

27169
35530
31188
37732
65217
28457
133147
22985
43141
10759

result:

ok 10 lines

Test #2:

score: 10
Accepted
time: 0ms
memory: 544kb

input:

10
eedleeeldeededlllleldleeeleleddleellele
kllrnnjqjniqqknjmlfcirjyrycfrkyqqjrky
uksfueafjuarusziepe...

output:

66808
20895
14900
37820
39914
38054
29364
37426
38775
29747

result:

ok 10 lines

Test #3:

score: 10
Accepted
time: 0ms
memory: 552kb

input:

10
aaqzqvvvvzaqvazzvqqzqzavaaavvqaqqqvaqavvavvaavzvqzavaqvzvaazavqavazzvqvqazzvzvqqaqaaqqazqaqqzzzza...

output:

6230886
3556080
11774834
3833447
8206626
3621091
5300328
6484259
3025216
18509610

result:

ok 10 lines

Test #4:

score: 10
Accepted
time: 1ms
memory: 584kb

input:

10
bsppzzcusncccbbpgguszngssnzncsnzpppbpuuczgcbucpupcubbzubsncncpbgbuzungnznsnpncpbugzcpguungzgcnbng...

output:

559443824
305794405
414279981
912202469
497470943
263140764
422669314
204178180
579056344
460822521

result:

ok 10 lines

Test #5:

score: 10
Accepted
time: 0ms
memory: 580kb

input:

10
pzrpbfgjbnqhbpzohubzunqjnujfbfgazjqeaqhjgppqnogagegebuebhbeoeboouoojhbhaahjooggrozeephgqfrzrfrpjz...

output:

442803205
483459867
245377898
502317569
156660068
301473465
396310915
489306288
862513697
753896393

result:

ok 10 lines

Test #6:

score: 10
Accepted
time: 653ms
memory: 544kb

input:

100000
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...

output:

341665830
471661
1999742
543480
459540
202296822
191363172
1241848
713235
369157
575809
170913820
68...

result:

ok 100000 lines

Test #7:

score: 10
Accepted
time: 452ms
memory: 580kb

input:

10000
iqtuiwnrdznudrwdznuwoyhzhhmiqytqhdqjuhihyuyrmwqurmdzdwiidomqrihqrjzyjwytjhznuwuhiojnhiduhytjir...

output:

452745570
395658802
415729637
581286624
608938037
896800719
444684505
913683462
444333468
228535301
...

result:

ok 10000 lines

Test #8:

score: 10
Accepted
time: 474ms
memory: 960kb

input:

1000
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

845573779
254782300
56185577
239721206
427653199
812292186
496897443
160197728
268511769
327773907
7...

result:

ok 1000 lines

Test #9:

score: 0
Wrong Answer
time: 468ms
memory: 4736kb

input:

100
yuuxiorshssxoiyxrsxyyyuxsuyuhsruhxisoyiuuixhrsxuxyyxxosihhyisxxohoyiiurxhixrruryiihxhsxhxuhoroou...

output:

732636589
377635994
204944545
-197342622
855220417
505651421
500433866
804284443
619658341
-58289597...

result:

wrong answer 4th lines differ - expected: '800901731', found: '-197342622'

Test #10:

score: 0
Runtime Error

input:

10
qvvvvqqgqgvvvgqvgqvqqwqgwqvqggvgqqqgqvwwggwwqqqqqwvwqggqvgqqvvvvvwqvqvvgvvqgvwqggwqqvvwwvvgwwwgqg...

output:


result: