QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#44280 | #3293. 优秀的拆分 | myee | 100 ✓ | 576ms | 11076kb | C++11 | 3.6kb | 2022-08-14 21:04:48 | 2022-08-14 21:04:51 |
Judging History
answer
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
typedef long long llt;
typedef unsigned uint;typedef unsigned long long ullt;
typedef bool bol;typedef char chr;typedef void voi;
typedef double dbl;
template<typename T=uint,typename len_def=uint>
class Min_ST
{
public:
voi bzr(std::vector<T>V)
{
ST.clear();len_def k=V.size();
for(len_def i=0;i<k;i++)ST.push_back(std::vector<T>()),ST[i].push_back(V[i]);
for(len_def f=2;f<=k;f<<=1)for(len_def i=0;i+f<=k;i++)
ST[i].push_back(std::min(ST[i].back(),ST[i+f/2].back()));
}
T Find(len_def Lnum,len_def Rnum)//log2不能打成log啊QAQ
{
len_def k=log2(Rnum-Lnum);return std::min(ST[Lnum][k],ST[Rnum-((len_def)1<<k)][k]);
}
private:
std::vector<std::vector<T> >ST;
};
template<typename T=chr,typename len_def=uint>
class SA
{
public:
voi bzr(T*User,len_def n)
{
S.clear(),rk.clear(),sa.clear(),h.clear(),lcp_ready();
for(len_def i=0;i<n;i++)S.push_back(User[i]),rk.push_back(0),sa.push_back(0),h.push_back(0);
//倍增法求sa
len_def done=1;
while(done<2*n)
{
if(done!=1)
{
typedef std::pair<len_def,len_def>P;
typedef std::pair<P,len_def>P2;
std::vector<P2>q,tmp;std::vector<len_def>cnt;
for(len_def i=0;i<n;i++)q.push_back(P2(P(rk[i]+1,(i+done/2<n)?rk[i+done/2]+1:0),i)),tmp.push_back(P2());
for(len_def i=0;i<=n;i++)cnt.push_back(0);
for(len_def i=0;i<n;i++)cnt[q[i].first.second]++;
for(len_def i=1;i<=n;i++)cnt[i]+=cnt[i-1];
for(len_def i=0;i<n;i++)tmp[--cnt[q[i].first.second]]=q[i];
cnt.clear();for(len_def i=0;i<=n;i++)cnt.push_back(0);
for(len_def i=0;i<n;i++)cnt[tmp[i].first.first]++;
for(len_def i=1;i<=n;i++)cnt[i]+=cnt[i-1];
for(len_def i=n-1;i+1;i--)q[--cnt[tmp[i].first.first]]=tmp[i];
for(len_def i=0;i<n;i++)rk[q[i].second]=(i&&q[i].first==q[i-1].first)?rk[q[i-1].second]:i;
}
else
{
typedef std::pair<T,len_def>P;
std::vector<P>q;
for(len_def i=0;i<n;i++)q.push_back(P(User[i],i));
std::sort(q.begin(),q.end());
for(len_def i=0;i<n;i++)rk[q[i].second]=(i&&q[i].first==q[i-1].first)?rk[q[i-1].second]:i;
}
done<<=1;
}
for(len_def i=0;i<n;i++)sa[rk[i]]=i;
len_def k=0;
for(len_def i=0;i<n;i++)
{
if(k)k--;
if(rk[i])
{
len_def j=sa[rk[i]-1];
while(i+k<n&&j+k<n&&User[i+k]==User[j+k])k++;
h[rk[i]]=k;
}
}
}
inline len_def rank(len_def num){return rk[num];}
inline len_def s_a(len_def num){return sa[num];}
inline len_def height(len_def num){return h[num];}
inline voi lcp_ready(){p.bzr(h);}
len_def lcp(len_def a,len_def b)
{
if(rk[a]>rk[b])std::swap(a,b);
return(a==b)?S.size()-a:p.Find(rk[a]+1,rk[b]+1);
}
private:
std::vector<T>S;std::vector<len_def>rk,sa,h;
Min_ST<len_def,len_def>p;
};
SA<>s1,s2;
chr C1[30005],C2[30005];
uint L[30005]={0},R[30005]={0};
int main()
{
uint t,n;ullt ans;scanf("%u",&t);
while(t--)
{
scanf("%s",C1),s1.bzr(C1,n=strlen(C1)),s1.lcp_ready(),ans=0;
for(uint i=0;i<n;i++)C2[i]=C1[n-i-1],L[i]=R[i]=0;s2.bzr(C2,n),s2.lcp_ready();
for(uint k=1;(k<<1)<=n;k++)
{
uint p,q=k-1,l,r;
while(q+k<n)
{
p=q,q+=k;
if(C1[p]==C1[q])
{
r=std::min(s1.lcp(p,q),k),l=std::min(s2.lcp(n-p-1,n-q-1),k);
for(uint i=p-l+1;i+k<=p+r;i++)R[i]++;
for(uint i=q+r-1;i+l>=q+k;i--)L[i]++;
}
}
}
for(uint i=1;i+1<n;i++)ans+=(ullt)L[i]*R[i+1];
printf("%llu\n",ans);
}
return 0;
}
详细
Test #1:
score: 5
Accepted
time: 0ms
memory: 3344kb
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: 2ms
memory: 3336kb
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: 23ms
memory: 3720kb
input:
10 kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk...
output:
92601930 126763350 233408728 111659395 147774025 41791750 62056280 198982282 172593608 298613460
result:
ok 10 numbers
Test #4:
score: 5
Accepted
time: 21ms
memory: 3724kb
input:
10 nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn...
output:
241383298 63369600 53220335 75846485 53073182 47276061 287600152 128609208 205431400 71461299
result:
ok 10 numbers
Test #5:
score: 5
Accepted
time: 0ms
memory: 3276kb
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: 3232kb
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: 0ms
memory: 3176kb
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: 2ms
memory: 3264kb
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: 2ms
memory: 3228kb
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: 2ms
memory: 3236kb
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: 3252kb
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: 3288kb
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: 2ms
memory: 3304kb
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: 3308kb
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: 5ms
memory: 3304kb
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: 4ms
memory: 3348kb
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: 3356kb
input:
10 iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii...
output:
1391040 981179 345415 50677 52576 227 28 413 144 50
result:
ok 10 numbers
Test #18:
score: 5
Accepted
time: 10ms
memory: 3536kb
input:
10 fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...
output:
38263590 33623065 4070400 510708 624588 2102 1074 299 408 1538
result:
ok 10 numbers
Test #19:
score: 5
Accepted
time: 19ms
memory: 3832kb
input:
10 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...
output:
245030555 46877978 4884100 14318590 12858978 5063 5381 7598 4729 5228
result:
ok 10 numbers
Test #20:
score: 5
Accepted
time: 576ms
memory: 11076kb
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