QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#67550 | #3293. 优秀的拆分 | alpha1022 | 100 ✓ | 115ms | 8304kb | C++23 | 3.2kb | 2022-12-10 17:12:29 | 2022-12-10 17:12:30 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 3e4;
const int LG = 15;
int T,n;
int lg2[N + 5];
int a[N + 5],b[N + 5];
long long ans;
struct SuffixArray
{
int n,m;
char a[N + 5];
int sa[N + 5],rk[N * 2 + 5],tpr[N * 2 + 5],c[N + 5],height[N + 5];
int st[N + 5][LG + 5];
void build()
{
memset(sa,0,sizeof sa);
memset(rk,0,sizeof rk);
memset(tpr,0,sizeof tpr);
n = strlen(a + 1),m = 127;
memset(c,0,sizeof c);
for(register int i = 1;i <= n;++i)
++c[rk[i] = a[i]];
for(register int i = 1;i <= m;++i)
c[i] += c[i - 1];
for(register int i = n;i;--i)
sa[c[rk[i]]--] = i;
for(register int w = 1,p = 0;p < n;w <<= 1,m = p)
{
p = 0;
for(register int i = 1;i <= w;++i)
tpr[++p] = n - w + i;
for(register int i = 1;i <= n;++i)
if(sa[i] > w)
tpr[++p] = sa[i] - w;
memset(c,0,sizeof c);
for(register int i = 1;i <= n;++i)
++c[rk[i]];
for(register int i = 1;i <= m;++i)
c[i] += c[i - 1];
for(register int i = n;i;--i)
sa[c[rk[tpr[i]]]--] = tpr[i];
swap(rk,tpr),rk[sa[1]] = p = 1;
for(register int i = 2;i <= n;++i)
rk[sa[i]] = tpr[sa[i]] == tpr[sa[i - 1]] && tpr[sa[i] + w] == tpr[sa[i - 1] + w] ? p : ++p;
}
for(register int i = 1,k = 0;i <= n;++i)
{
k -= (bool)k;
for(;i + k <= n && sa[rk[i] - 1] + k <= n && a[i + k] == a[sa[rk[i] - 1] + k];++k);
height[rk[i]] = st[rk[i]][0] = k;
}
for(register int i = 1;i <= LG;++i)
for(register int j = 1;j + (1 << i) - 1 <= n;++j)
st[j][i] = min(st[j][i - 1],st[j + (1 << i - 1)][i - 1]);
}
int query(int l,int r)
{
l = rk[l],r = rk[r];
if(l > r)
swap(l,r);
++l;
int lg = lg2[r - l + 1];
return min(st[l][lg],st[r - (1 << lg) + 1][lg]);
}
} s,t;
int main()
{
for(register int i = 2;i <= N;++i)
lg2[i] = lg2[i / 2] + 1;
scanf("%d",&T);
while(T--)
{
scanf("%s",s.a + 1);
n = strlen(s.a + 1);
for(register int i = 1;i <= n;++i)
t.a[i] = s.a[n - i + 1];
s.build(),t.build();
memset(a,0,sizeof a),memset(b,0,sizeof b);
for(register int w = 1;w <= n / 2;++w)
for(register int i = w;i <= n;i += w)
{
int l = i,r = i + w;
int lcp = s.query(l,r),lcs = t.query(n - r + 2,n - l + 2);
lcp = min(lcp,w),lcs = min(lcs,w - 1);
if(lcp + lcs >= w)
++b[l - lcs],--b[l - w + lcp + 1],
++a[r + w - lcs - 1],--a[r + lcp];
}
for(register int i = 1;i <= n;++i)
a[i] += a[i - 1],b[i] += b[i - 1];
ans = 0;
for(register int i = 1;i < n;++i)
ans += a[i] * b[i + 1];
printf("%lld\n",ans);
}
}
詳細信息
Test #1:
score: 5
Accepted
time: 6ms
memory: 3456kb
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: 5ms
memory: 3400kb
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: 9ms
memory: 3676kb
input:
10 kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk...
output:
92601930 126763350 233408728 111659395 147774025 41791750 62056280 198982282 172593608 298613460
result:
ok 10 numbers
Test #4:
score: 5
Accepted
time: 9ms
memory: 3616kb
input:
10 nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn...
output:
241383298 63369600 53220335 75846485 53073182 47276061 287600152 128609208 205431400 71461299
result:
ok 10 numbers
Test #5:
score: 5
Accepted
time: 3ms
memory: 3388kb
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: 1ms
memory: 3384kb
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: 1ms
memory: 3320kb
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: 1ms
memory: 3412kb
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: 4ms
memory: 3404kb
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: 1ms
memory: 3412kb
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: 4ms
memory: 3396kb
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: 4ms
memory: 3320kb
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: 5ms
memory: 3336kb
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: 4ms
memory: 3404kb
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: 2ms
memory: 3420kb
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: 1ms
memory: 3400kb
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: 2ms
memory: 3464kb
input:
10 iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii...
output:
1391040 981179 345415 50677 52576 227 28 413 144 50
result:
ok 10 numbers
Test #18:
score: 5
Accepted
time: 7ms
memory: 3464kb
input:
10 fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...
output:
38263590 33623065 4070400 510708 624588 2102 1074 299 408 1538
result:
ok 10 numbers
Test #19:
score: 5
Accepted
time: 9ms
memory: 3648kb
input:
10 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...
output:
245030555 46877978 4884100 14318590 12858978 5063 5381 7598 4729 5228
result:
ok 10 numbers
Test #20:
score: 5
Accepted
time: 115ms
memory: 8304kb
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