QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#276704 | #3293. 优秀的拆分 | SoyTony | 100 ✓ | 136ms | 15052kb | C++14 | 3.6kb | 2023-12-06 09:45:10 | 2023-12-06 09:45:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=5e4+10;
inline int read(){
int x=0,w=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
while(c<='9'&&c>='0'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
return x*w;
}
int t;
int n;
struct SuffixArray{
char s[maxn];
int sa[maxn],rk[maxn<<1],cnt[maxn],oldsa[maxn],oldrk[maxn<<1],tmp[maxn];
int height[maxn];
int st[maxn][18];
inline bool cmp(int x,int y,int l){
return oldrk[x]==oldrk[y]&&oldrk[x+l]==oldrk[y+l];
}
inline void init(){
memset(s,0,sizeof(s));
memset(sa,0,sizeof(sa));
memset(rk,0,sizeof(rk));
memset(cnt,0,sizeof(cnt));
memset(oldsa,0,sizeof(oldsa));
memset(oldrk,0,sizeof(oldrk));
memset(tmp,0,sizeof(tmp));
memset(height,0,sizeof(height));
memset(st,0,sizeof(st));
}
inline void build(){
int siz=max(n,127);
for(int i=1;i<=n;++i) ++cnt[rk[i]=s[i]];
for(int i=1;i<=siz;++i) cnt[i]+=cnt[i-1];
for(int i=n;i>=1;--i) sa[cnt[rk[i]]--]=i;
for(int l=1,k;;l<<=1){
k=0;
for(int i=n;i+l>n;--i) oldsa[++k]=i;
for(int i=1;i<=n;++i) if(sa[i]>l) oldsa[++k]=sa[i]-l;
memset(cnt,0,sizeof(cnt));
for(int i=1;i<=n;++i) ++cnt[tmp[i]=rk[oldsa[i]]];
for(int i=1;i<=siz;++i) cnt[i]+=cnt[i-1];
for(int i=n;i>=1;--i) sa[cnt[tmp[i]]--]=oldsa[i];
for(int i=1;i<=n;++i) oldrk[i]=rk[i];
k=0;
for(int i=1;i<=n;++i) rk[sa[i]]=cmp(sa[i],sa[i-1],l)?k:++k;
if(k==n) break;
siz=k;
}
for(int i=1,k=0;i<=n;++i){
if(k) --k;
while(s[i+k]==s[sa[rk[i]-1]+k]) ++k;
height[rk[i]]=k;
st[rk[i]][0]=k;
}
for(int k=1;k<=16;++k){
for(int i=1;i+(1<<k)-1<=n;++i){
st[i][k]=min(st[i][k-1],st[i+(1<<k-1)][k-1]);
}
}
}
inline int query(int l,int r){
int rkl=min(rk[l],rk[r]),rkr=max(rk[l],rk[r]);
++rkl;
int k=log2(rkr-rkl+1);
return min(st[rkl][k],st[rkr-(1<<k)+1][k]);
}
}SA1,SA2;
int f[maxn],g[maxn];
ll ans;
int main(){
t=read();
while(t--){
SA1.init();
SA2.init();
scanf("%s",SA1.s+1);
n=strlen(SA1.s+1);
for(int i=1;i<=n;++i) SA2.s[i]=SA1.s[n-i+1];
SA1.build();
SA2.build();
memset(f,0,sizeof(f));
memset(g,0,sizeof(g));
for(int l=1;l*2<=n;++l){
// printf("***l=%d***\n",l);
for(int i=0;(i+1)*l+1<=n;++i){
int x=i*l+1,y=(i+1)*l+1;
// printf("(%d %d) ",x,y);
int lcp=SA1.query(x,y),lcs=SA2.query(n-x+1,n-y+1);
// printf("lcs=%d lcp=%d\n",lcs,lcp);
if(lcp+lcs-1<l) continue;
int L=x-lcs+1,R=y+lcp-1-2*l+1;
if(L<x-l+1) L=x-l+1;
if(R>x) R=x;
// printf("[%d %d] ",L,R);
++f[L],--f[R+1];
L=x-lcs+1+2*l-1,R=y+lcp-1;
if(L<y) L=y;
if(R>y+l-1) R=y+l-1;
// printf("[%d %d]\n",L,R);
++g[L],--g[R+1];
}
}
for(int i=1;i<=n;++i) f[i]+=f[i-1],g[i]+=g[i-1];
// for(int i=1;i<=n;++i) printf("%d %d\n",f[i],g[i]);
ans=0;
for(int i=1;i<n;++i) ans+=1ll*g[i]*f[i+1];
printf("%lld\n",ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 5ms
memory: 15048kb
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: 4ms
memory: 14896kb
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: 8ms
memory: 14976kb
input:
10 kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk...
output:
92601930 126763350 233408728 111659395 147774025 41791750 62056280 198982282 172593608 298613460
result:
ok 10 numbers
Test #4:
score: 5
Accepted
time: 8ms
memory: 15044kb
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: 14856kb
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: 2ms
memory: 14896kb
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: 3ms
memory: 14972kb
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: 3ms
memory: 14968kb
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: 3ms
memory: 14860kb
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: 3ms
memory: 15044kb
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: 3ms
memory: 14980kb
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: 3ms
memory: 15036kb
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: 3ms
memory: 14872kb
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: 3ms
memory: 15040kb
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: 3ms
memory: 15036kb
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: 3ms
memory: 15040kb
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: 7ms
memory: 14900kb
input:
10 iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii...
output:
1391040 981179 345415 50677 52576 227 28 413 144 50
result:
ok 10 numbers
Test #18:
score: 5
Accepted
time: 9ms
memory: 14852kb
input:
10 fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...
output:
38263590 33623065 4070400 510708 624588 2102 1074 299 408 1538
result:
ok 10 numbers
Test #19:
score: 5
Accepted
time: 8ms
memory: 15052kb
input:
10 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...
output:
245030555 46877978 4884100 14318590 12858978 5063 5381 7598 4729 5228
result:
ok 10 numbers
Test #20:
score: 5
Accepted
time: 136ms
memory: 15036kb
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