QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#457018#3293. 优秀的拆分_HKSR_0 175ms17724kbC++143.8kb2024-06-28 21:23:362024-06-28 21:23:36

Judging History

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

  • [2024-06-28 21:23:36]
  • 评测
  • 测评结果:0
  • 用时:175ms
  • 内存:17724kb
  • [2024-06-28 21:23:36]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
const int LEN=6e4;
int rk[LEN],rk2[LEN],sa[LEN],cnt[LEN];
int h[LEN];
int nw[LEN];
int loc[LEN];
int st[LEN][16];
const int LG=16;
int lg[LEN];
inline void clr(){memset(cnt,0,sizeof(cnt));}
inline void sct(){
    for(int i=1;i<LEN;i++)
        cnt[i]+=cnt[i-1];
}
inline void SA(string P){
    int m=P.size();
    P=" "+P;
    P=P+(char)(0);
    clr();
    for(int i=1;i<=m;i++)
        rk[i]=P[i],cnt[rk[i]]++,h[i]=0;
    sct();
    for(int i=1;i<=m;i++)
        sa[++cnt[rk[i]-1]]=i;
    for(int p=1;p<m;p<<=1){
        for(int i=1;i<=m;i++)
            rk2[i]=i+p<=m?rk[i+p]:0;
        clr();
        for(int i=1;i<=m;i++)cnt[rk[i]]++;
        sct();
        vector<int>T;
        for(int i=1;i<=m;i++)if(sa[i]+p>m)T.push_back(sa[i]);
        for(int i=1;i<=m;i++)if(sa[i]>p)T.push_back(sa[i]-p);
        for(int x:T)sa[++cnt[rk[x]-1]]=x;
        int cnt=0;
        for(int i=1;i<=m;i++){
            if(i==1||rk[sa[i]]!=rk[sa[i-1]]||rk2[sa[i]]!=rk2[sa[i-1]])
                cnt++;
            nw[sa[i]]=cnt;
        }
        for(int i=1;i<=m;i++)
            rk[i]=nw[i];
    }
    int t=0;
    for(int i=1;i<=m;i++){
        t=max(0ll,h[rk[i-1]]-1);
        if(rk[i]==1){t=0;h[rk[i]]=0;continue;}
        int l=sa[rk[i]-1];
        while(l+t<=m&&i+t<=m&&P[l+t]==P[i+t])t++;
        h[rk[i]]=t;
    }
    for(int i=1;i<=m;i++)st[i][0]=h[i];
    for(int j=1;j<LG;j++)
        for(int i=1;i+(1<<j)-1<=m;i++)
            st[i][j]=min(st[i][j-1],st[i+(1<<j-1)][j-1]);
}
inline int g(int l,int r){
    if(l>r)return 0;
    int p=lg[r-l+1];
    return min(st[l][p],st[r-(1<<p)+1][p]);
}
int n;
inline int lcp(int x,int y){
    if(x<=0||y<=0)return 0;
    
    x=rk[x],y=rk[y];
    if(x>y)swap(x,y);
    return g(x+1,y);
}
inline int lcp_rev(int x,int y){
    if(x<=0||y<=0||x>n||y>n)return 0;
    x=n-x+1,y=n-y+1;
    return lcp(x+n,y+n);
}
inline int lcp_ver(int x,int y){
    if(x<=0||y<=0||x>n||y>n)return 0;
    return lcp(x,y);
    
}
string s;
int bel[LEN];
int A[LEN],B[LEN];
int L[LEN],R[LEN];
signed main(){
    // freopen("uke.in","r",stdin);
    // freopen(".out","w",stdout);
    ios::sync_with_stdio(0);
    int t;
    cin>>t;
    for(int i=2;i<LEN;i++)
    lg[i]=lg[i>>1]+1;
    while(t--){
        string t;
        cin>>t;
        s=t;
        n=s.size();
        reverse(t.begin(),t.end());
        s=s+t;
        SA(s);
        for(int i=1;i<=n;i++)A[i]=B[i]=0;
            // cout<<lcp_ver(5,7)<<" "<<lcp_rev(4,6)<<endl;
        for(int s=1;s<=n;s++){
            int m=0;
            while(++m){
                L[m]=R[m-1]+1;
                R[m]=min(L[m]+s-1,n);
                if(R[m]==n)break;
            }
            L[m+1]=n+1;
            for(int i=2;i<=m;i++){
                int l=min(s,lcp_rev(R[i-1],R[i]));
                int r=min(s-1,lcp_ver(L[i],L[i+1]));
                if(l+r<s)continue;
                int pl=s-r,pr=l;
                
                // cout<<l<<" "<<r<<" "<<L[i]<<" "<<R[i]<<" "<<s<<endl;
                // cout<<pl<<" "<<pr<<" "<<L[i]-pr<<" "<<L[i]-pl<<endl;
                A[L[i]-pr]++;
                A[L[i]-pl+1]--;

                pl=s-pl,pr=s-pr;
                // cout<<pl<<" "<<pr<<" "<<R[i]+pr<<" "<<R[i]+pl<<endl;
                
                B[R[i]+pr]++;
                B[R[i]+pl+1]--;

            }
        }
        for(int i=1;i<=n;i++)A[i]+=A[i-1],B[i]+=B[i-1];
        // for(int i=1;i<=n;i++)
        // cout<<A[i]<<" ";
        // cout<<endl;
        // for(int i=1;i<=n;i++)
        // cout<<B[i]<<" ";
        // cout<<endl;
        int res=0;
        for(int i=2;i<=n-2;i++)
            res+=B[i]*A[i+1];
        cout<<res<<endl;
    }


    cout.flush();
    return 0;
}
/*

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 9824kb

input:

10
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk...

output:

623163
193221
1207101
799768
1091347
408233
236370
555446
312151
1261983

result:

wrong answer 1st numbers differ - expected: '462056', found: '623163'

Test #2:

score: 0
Wrong Answer
time: 5ms
memory: 8284kb

input:

10
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...

output:

498949
701279
391016
419990
551584
257820
244735
444788
590829
1491590

result:

wrong answer 1st numbers differ - expected: '369564', found: '498949'

Test #3:

score: 0
Wrong Answer
time: 11ms
memory: 12216kb

input:

10
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk...

output:

126776521
173248979
319559909
152486071
202012928
57154296
84742557
272385974
235912781
408352110

result:

wrong answer 1st numbers differ - expected: '92601930', found: '126776521'

Test #4:

score: 0
Wrong Answer
time: 7ms
memory: 9816kb

input:

10
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn...

output:

329824155
86566596
72719847
103701740
72530209
64426396
393489546
176072218
280831400
97704982

result:

wrong answer 1st numbers differ - expected: '241383298', found: '329824155'

Test #5:

score: 0
Wrong Answer
time: 3ms
memory: 8112kb

input:

10
nnnnnnnnnn
hzhzhzhzhz
zezezezeze
ndndndndnd
zvzvzvzvzv
bbbbbbbbbb
sgsgsgsgsg
fgfgfgfgfg
hxhxhxhxhx
fafafafafa

output:

38
4
4
4
4
38
4
4
4
4

result:

wrong answer 1st numbers differ - expected: '30', found: '38'

Test #6:

score: 0
Wrong Answer
time: 4ms
memory: 9732kb

input:

10
xxxxxxxxxx
wtwtwtwtwt
sososososo
xgxgxgxgxg
lblblblblb
rororororo
qfqfqfqfqf
qjqjqjqjqj
upupupupup
nynynynyny

output:

38
4
4
4
4
4
4
4
4
4

result:

wrong answer 1st numbers differ - expected: '30', found: '38'

Test #7:

score: 0
Wrong Answer
time: 2ms
memory: 8168kb

input:

10
jjjjjjjjjjjjjjjjjjjj
tgtgtgtgtg
mcomcomcomco
wthwthwthwth
aaitaaitaaitaait
pvaompvaompvaompvaom
ahahahahah
jwxmjwxmjwxmjwxm
pdfpdfpdfpdf
oiyfoiyfoiyfoiyf

output:

346
4
1
1
6
1
4
1
1
1

result:

wrong answer 1st numbers differ - expected: '285', found: '346'

Test #8:

score: 0
Wrong Answer
time: 0ms
memory: 8176kb

input:

10
iiiiiiiiiiiiiiiii
scscscscscscsc
bsobsobsobsobso
rppyrppyrppyrppy
xhnxhnxhnxhn
jfbjfbjfbjfb
tqtqtqtqtq
cdocdocdocdocdo
imgimgimgimg
zxzxzxzxzx

output:

239
19
6
5
1
1
4
6
1
4

result:

wrong answer 1st numbers differ - expected: '168', found: '239'

Test #9:

score: 0
Wrong Answer
time: 4ms
memory: 9996kb

input:

10
sssssssssssssssssssss
wawawawawawawawa
xlexlexlexlexlexlexle
cwqfcwqfcwqfcwqfcwqfcwqfcwqf
dappidappidappidappidappi
biwtbbiwtbbiwtbbiwtb
ipdbipdbipdbipdb
oyqjoyqjoyqjoyqj
miqozmiqozmiqozmiqoz
ofqgofqgofqgofqg

output:

456
24
21
29
15
3
1
1
1
1

result:

wrong answer 1st numbers differ - expected: '330', found: '456'

Test #10:

score: 0
Wrong Answer
time: 4ms
memory: 7760kb

input:

10
zzzzzzzzzzzzzzzzzzzzzzzzzzz
icicicicicicicicicicic
saasaasaasaasaasaasaa
znunznunznunznunznun
ttfhhttfhhttfhhttfhhttfhh
fqxqblfqxqblfqxqblfqxqblfqxqbl
xxpruxxpruxxpruxxpru
mpheqsmpheqsmpheqsmpheqs
ptvbemqptvbemqptvbemqptvbemq
nxykqknxykqknxykqknxykqk

output:

957
86
41
6
28
9
5
1
1
1

result:

wrong answer 1st numbers differ - expected: '728', found: '957'

Test #11:

score: 0
Wrong Answer
time: 4ms
memory: 10032kb

input:

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

output:

1615
1008
118
13
84
9
41
10
21
1

result:

wrong answer 1st numbers differ - expected: '1240', found: '1615'

Test #12:

score: 0
Wrong Answer
time: 0ms
memory: 7940kb

input:

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

output:

2124
152
60
42
49
39
17
1
1
5

result:

wrong answer 1st numbers differ - expected: '1632', found: '2124'

Test #13:

score: 0
Wrong Answer
time: 5ms
memory: 9968kb

input:

10
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
xwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxw
rslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrsl
iimeiimeiimeiimeiimeiimeiimeiimeiimeiimeiimeiime...

output:

35153
6731
1449
1099
906
617
63
124
34
90

result:

wrong answer 1st numbers differ - expected: '25585', found: '35153'

Test #14:

score: 0
Wrong Answer
time: 5ms
memory: 9744kb

input:

10
rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
ozozozozozozozozozozozozozozozozozozozozozozozozozozozozozozozoz
ysvysvysvysvysvysvysvysvysvysvysvysvysvysvysvysvysvysv
ipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbd
x...

output:

25403
2521
578
1912
118
7
529
124
144
61

result:

wrong answer 1st numbers differ - expected: '19019', found: '25403'

Test #15:

score: 0
Wrong Answer
time: 5ms
memory: 8340kb

input:

10
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
vzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvz
yzkyzkyzkyzkyzk...

output:

210113
19234
8040
13942
3445
72
114
37
17
6

result:

wrong answer 1st numbers differ - expected: '155155', found: '210113'

Test #16:

score: 0
Wrong Answer
time: 5ms
memory: 8004kb

input:

10
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
bxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbx...

output:

383087
50144
27011
13942
20853
80
73
59
21
26

result:

wrong answer 1st numbers differ - expected: '281295', found: '383087'

Test #17:

score: 0
Wrong Answer
time: 7ms
memory: 11836kb

input:

10
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii...

output:

1898669
994050
350536
51892
53489
227
28
413
144
50

result:

wrong answer 1st numbers differ - expected: '1391040', found: '1898669'

Test #18:

score: 0
Wrong Answer
time: 4ms
memory: 7936kb

input:

10
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...

output:

52429611
45994568
4097514
516828
629749
2102
1076
299
408
1552

result:

wrong answer 1st numbers differ - expected: '38263590', found: '52429611'

Test #19:

score: 0
Wrong Answer
time: 11ms
memory: 8128kb

input:

10
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...

output:

334871167
47049243
4914957
14381221
12899427
5076
5381
7600
4729
5228

result:

wrong answer 1st numbers differ - expected: '245030555', found: '334871167'

Test #20:

score: 0
Wrong Answer
time: 175ms
memory: 17724kb

input:

10
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy...

output:

770252343738
161494472454
104736452506
70168734212
40850625326
6057662
2820455
3357867
2628256
10884

result:

wrong answer 1st numbers differ - expected: '563349754956', found: '770252343738'