QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#68279#3293. 优秀的拆分Lenstar100 ✓98ms21988kbC++143.5kb2022-12-15 15:49:162022-12-15 15:49:19

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-15 15:49:19]
  • 评测
  • 测评结果:100
  • 用时:98ms
  • 内存:21988kb
  • [2022-12-15 15:49:16]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define N 300010
inline int read() {
    int x = 0;
    char ch = getchar();

    while (!isdigit(ch))
        ch = getchar();

    while (isdigit(ch))
        x = x * 10 + ch - '0', ch = getchar();

    return x;
}
struct SuffixArray {
    char s[N];
    int a[N], b[N], sa[N], tax[N], hgt[N], Log[N], f[21][N];
    inline void sort(int *a, int *b, int n, int m) {
        for (int i = 1; i <= m; i++)
            tax[i] = 0;

        for (int i = 1; i <= n; i++)
            tax[a[i]]++;

        for (int i = 1; i <= m; i++)
            tax[i] += tax[i - 1];

        for (int i = n; i >= 1; i--)
            sa[tax[a[b[i]]]--] = b[i];
    }
    inline int cmp(int *f, int x, int y, int k) {
        return f[x] == f[y] && f[x + k] == f[y + k];
    }
    inline void build(char *s, int n) {
        int m = 0;
        memset(sa, 0, sizeof(sa));
        memset(a, 0, sizeof(a));
        memset(b, 0, sizeof(b));
        memset(tax, 0, sizeof(tax));
        memset(hgt, 0, sizeof(hgt));

        for (int i = 1; i <= n; i++)
            m = max(m, a[i] = s[i] - '0'), b[i] = i;

        sort(a, b, n, m);

        for (int p = 0, j = 1; p < n; j <<= 1, m = p) {
            p = 0;

            for (int i = 1; i <= j; i++)
                b[++p] = n - j + i;

            for (int i = 1; i <= n; i++)
                if (sa[i] > j)
                    b[++p] = sa[i] - j;

            sort(a, b, n, m), swap(a, b), a[sa[1]] = p = 1;

            for (int i = 2; i <= n; i++)
                a[sa[i]] = cmp(b, sa[i], sa[i - 1], j) ? p : ++p;

            // printf("%d\n",p);
        }

        // for (int i=1;i<=n;i++) printf("%d ",sa[i]);
        for (int i = 1, j = 0; i <= n; i++) {
            if (j)
                j--;

            while (s[i + j] == s[sa[a[i] - 1] + j])
                j++;

            hgt[a[i]] = j;
        }

        // for (int i=1;i<=n;i++) printf("%d ",a[i]);puts("");
        buildST(n);
    }
    inline void buildST(int n) {
        Log[0] = -1;

        for (int i = 1; i <= n; i++)
            f[0][i] = hgt[i], Log[i] = Log[i >> 1] + 1;

        for (int j = 1; j <= Log[n]; j++)
            for (int i = 1; i + (1 << j) - 1 <= n; i++)
                f[j][i] = min(f[j - 1][i], f[j - 1][i + (1 << j - 1)]);
    }
    inline int ask(int l, int r) {
        int x = min(a[l], a[r]) + 1, y = max(a[l], a[r]), w = Log[y - x + 1];
        return min(f[w][x], f[w][y - (1 << w) + 1]);
    }
} A, B;
char s[N];
int f[N], g[N];
inline void update(int *f, int l, int r) {
    f[l]++, f[r]--;
}
int main() {
    int T = read();

    while (T--) {
        scanf("%s", s + 1);
        int n = strlen(s + 1);
        A.build(s, n), reverse(s + 1, s + n + 1), B.build(s, n);
        memset(f, 0, sizeof(f)), memset(g, 0, sizeof(g));

        for (int len = 1; len <= n / 2; len++) {
            for (int i = len, j = len << 1; j <= n; i += len, j += len) {
                int lcp = min(A.ask(i, j), len), lcs = min(B.ask(n - i + 2, n - j + 2), len - 1);
                int t = lcp + lcs - len + 1;

                if (t > 0)
                    update(g, i - lcs, i - lcs + t), update(f, j + lcp - t, j + lcp);
            }
        }

        long long ans = 0;

        for (int i = 1; i <= n; i++)
            f[i] += f[i - 1], g[i] += g[i - 1];

        for (int i = 1; i <= n; i++)
            ans += 1LL * f[i] * g[i + 1];

        printf("%lld\n", ans);
    }

    return 0;
}

详细

Test #1:

score: 5
Accepted
time: 32ms
memory: 18392kb

input:

10
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk...

output:

462056
140600
875978
575960
811035
299536
173880
414090
227128
924490

result:

ok 10 numbers

Test #2:

score: 5
Accepted
time: 24ms
memory: 18460kb

input:

10
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...

output:

369564
513590
285760
308945
408312
190568
180441
328350
437635
1091574

result:

ok 10 numbers

Test #3:

score: 5
Accepted
time: 39ms
memory: 18256kb

input:

10
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk...

output:

92601930
126763350
233408728
111659395
147774025
41791750
62056280
198982282
172593608
298613460

result:

ok 10 numbers

Test #4:

score: 5
Accepted
time: 31ms
memory: 18368kb

input:

10
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn...

output:

241383298
63369600
53220335
75846485
53073182
47276061
287600152
128609208
205431400
71461299

result:

ok 10 numbers

Test #5:

score: 5
Accepted
time: 15ms
memory: 18428kb

input:

10
nnnnnnnnnn
hzhzhzhzhz
zezezezeze
ndndndndnd
zvzvzvzvzv
bbbbbbbbbb
sgsgsgsgsg
fgfgfgfgfg
hxhxhxhxhx
fafafafafa

output:

30
3
3
3
3
30
3
3
3
3

result:

ok 10 numbers

Test #6:

score: 5
Accepted
time: 11ms
memory: 18160kb

input:

10
xxxxxxxxxx
wtwtwtwtwt
sososososo
xgxgxgxgxg
lblblblblb
rororororo
qfqfqfqfqf
qjqjqjqjqj
upupupupup
nynynynyny

output:

30
3
3
3
3
3
3
3
3
3

result:

ok 10 numbers

Test #7:

score: 5
Accepted
time: 18ms
memory: 18344kb

input:

10
jjjjjjjjjjjjjjjjjjjj
tgtgtgtgtg
mcomcomcomco
wthwthwthwth
aaitaaitaaitaait
pvaompvaompvaompvaom
ahahahahah
jwxmjwxmjwxmjwxm
pdfpdfpdfpdf
oiyfoiyfoiyfoiyf

output:

285
3
1
1
5
1
3
1
1
1

result:

ok 10 numbers

Test #8:

score: 5
Accepted
time: 16ms
memory: 18228kb

input:

10
iiiiiiiiiiiiiiiii
scscscscscscsc
bsobsobsobsobso
rppyrppyrppyrppy
xhnxhnxhnxhn
jfbjfbjfbjfb
tqtqtqtqtq
cdocdocdocdocdo
imgimgimgimg
zxzxzxzxzx

output:

168
13
4
5
1
1
3
4
1
3

result:

ok 10 numbers

Test #9:

score: 5
Accepted
time: 15ms
memory: 18176kb

input:

10
sssssssssssssssssssss
wawawawawawawawa
xlexlexlexlexlexlexle
cwqfcwqfcwqfcwqfcwqfcwqfcwqf
dappidappidappidappidappi
biwtbbiwtbbiwtbbiwtb
ipdbipdbipdbipdb
oyqjoyqjoyqjoyqj
miqozmiqozmiqozmiqoz
ofqgofqgofqgofqg

output:

330
22
18
23
14
3
1
1
1
1

result:

ok 10 numbers

Test #10:

score: 5
Accepted
time: 17ms
memory: 18168kb

input:

10
zzzzzzzzzzzzzzzzzzzzzzzzzzz
icicicicicicicicicicic
saasaasaasaasaasaasaa
znunznunznunznunznun
ttfhhttfhhttfhhttfhhttfhh
fqxqblfqxqblfqxqblfqxqblfqxqbl
xxpruxxpruxxpruxxpru
mpheqsmpheqsmpheqsmpheqs
ptvbemqptvbemqptvbemqptvbemq
nxykqknxykqknxykqknxykqk

output:

728
70
36
5
26
7
5
1
1
1

result:

ok 10 numbers

Test #11:

score: 5
Accepted
time: 15ms
memory: 18236kb

input:

10
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
ibibibibibibibibibibibibibibibibibibibibibibibib
xinxinxinxinxinxinxinxinxinxinxin
ivlwivlwivlwivlwivlwivlw
cxrvucxrvucxrvucxrvucxrvucxrvucxrvucxrvucxrvu
jzqfmgjzqfmgjzqfmgjzqfmgjzqfmg
nqctlysnqctlysnqctlysnqctlysnqctlysnqctlysnqctlys
kuizuntnkuizuntnkuizuntnkuizu...

output:

1240
946
100
11
76
7
38
9
18
1

result:

ok 10 numbers

Test #12:

score: 5
Accepted
time: 26ms
memory: 18288kb

input:

10
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
dvdvdvdvdvdvdvdvdvdvdvdvdv
jhyjhyjhyjhyjhyjhyjhyjhyjhy
dkbjdkbjdkbjdkbjdkbjdkbjdkbjdkbj
ezlbtezlbtezlbtezlbtezlbtezlbtezlbtezlbt
efwduoefwduoefwduoefwduoefwduoefwduoefwduo
eqgdlgxeqgdlgxeqgdlgxeqgdlgxeqgdlgxeqgdlgx
mwuoqleamwuoqleamwuoqleamwuoqlea
gwcbhodfpgwcb...

output:

1632
125
48
38
46
33
17
1
1
5

result:

ok 10 numbers

Test #13:

score: 5
Accepted
time: 23ms
memory: 18060kb

input:

10
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
xwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxw
rslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrsl
iimeiimeiimeiimeiimeiimeiimeiimeiimeiimeiimeiime...

output:

25585
6391
1386
1014
876
567
62
118
33
86

result:

ok 10 numbers

Test #14:

score: 5
Accepted
time: 20ms
memory: 18304kb

input:

10
rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
ozozozozozozozozozozozozozozozozozozozozozozozozozozozozozozozoz
ysvysvysvysvysvysvysvysvysvysvysvysvysvysvysvysvysvysv
ipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbd
x...

output:

19019
2360
540
1826
110
7
511
118
132
53

result:

ok 10 numbers

Test #15:

score: 5
Accepted
time: 21ms
memory: 18220kb

input:

10
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
vzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvz
yzkyzkyzkyzkyzk...

output:

155155
18445
7600
13475
3328
72
114
37
17
6

result:

ok 10 numbers

Test #16:

score: 5
Accepted
time: 29ms
memory: 18328kb

input:

10
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
bxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbx...

output:

281295
48503
26100
13475
20516
80
72
59
21
26

result:

ok 10 numbers

Test #17:

score: 5
Accepted
time: 25ms
memory: 18340kb

input:

10
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii...

output:

1391040
981179
345415
50677
52576
227
28
413
144
50

result:

ok 10 numbers

Test #18:

score: 5
Accepted
time: 28ms
memory: 18292kb

input:

10
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...

output:

38263590
33623065
4070400
510708
624588
2102
1074
299
408
1538

result:

ok 10 numbers

Test #19:

score: 5
Accepted
time: 34ms
memory: 18488kb

input:

10
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...

output:

245030555
46877978
4884100
14318590
12858978
5063
5381
7598
4729
5228

result:

ok 10 numbers

Test #20:

score: 5
Accepted
time: 98ms
memory: 21988kb

input:

10
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy...

output:

563349754956
161455324997
76621205738
70150901846
40842068960
6056659
2820346
3357795
2628223
10884

result:

ok 10 numbers

Extra Test:

score: 0
Extra Test Passed