QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#469254 | #6816. Invincible Hotwheels | grass8cow | AC ✓ | 976ms | 415928kb | C++17 | 2.6kb | 2024-07-09 16:47:18 | 2024-07-09 16:47:19 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,fi[2010000],L[2010000];
char c[2010000];
int ch[2001000][26],cn=1,id[2001000],fail[2010000],po[2010000][2],is[2010000];
vector<int>g[2010000];
int dfn[2010000],sz[2010000];
void dfs(int x){
dfn[x]=++dfn[0],sz[x]=1;
for(int v:g[x])dfs(v),sz[x]+=sz[v];
}
#define pb push_back
void build(){
queue<int>q;for(int i=0;i<26;i++)if(!ch[1][i])ch[1][i]=1;
else fail[ch[1][i]]=1,q.push(ch[1][i]);
while(!q.empty()){
int u=q.front(),f=fail[u];q.pop();
if(id[u])po[u][0]=u,po[u][1]=po[f][0];
else po[u][0]=po[f][0],po[u][1]=po[f][1];
for(int i=0;i<26;i++){
if(!ch[u][i])ch[u][i]=ch[f][i];
else fail[ch[u][i]]=ch[f][i],q.push(ch[u][i]);
}
}
for(int i=2;i<=cn;i++)g[fail[i]].pb(i);
dfs(1);
}
struct T1{
int tr[2010000];
inline void ad(int x,int z){for(;x<=cn;x+=(x&-x))tr[x]+=z;}
inline int ask(int x){
int s=0;
for(;x;x-=(x&-x))s+=tr[x];
return s;
}
}T;
int cc(int a,int b){
if(a==-1||b==-1)return -1;
if(!a||!b)return a+b;
if(a==b)return a;
return -1;
}
struct T2{
int tr[2010000];int O;
inline void inn(int N){O=N;for(int i=1;i<=N;i++)tr[i]=0;}
inline void ad(int x,int z){for(;x<=O;x+=(x&-x))tr[x]=cc(tr[x],z);}
inline int ask(int x){
int s=0;
for(;x;x-=(x&-x))s=cc(s,tr[x]);return s;
}
}B;
bool qc[2010000];int xp[2010000];
vector<int>G[2001000];
struct ed{int l,r,c;}a[2010000];
int main(){
scanf("%d",&n);
for(int i=1,e=0;i<=n;i++){
fi[i]=e;
scanf("%s",c+1+e);
L[i]=strlen(c+1+e);
int u=1;
for(int j=e+1;j<=e+L[i];j++){
int p=c[j]-'a';
if(!ch[u][p])ch[u][p]=++cn;
u=ch[u][p];
}
id[u]=i,e+=L[i],is[i]=u;
}
build();
int ans=0;
for(int i=1;i<=n;i++){
vector<int>J;
int m=0;
for(int j=1,u=1;j<=L[i];j++){
u=ch[u][c[j+fi[i]]-'a'];
if(j==L[i])u=fail[u];
if(po[u][1])T.ad(dfn[fail[po[u][1]]],1);//注意后面清了
for(int o=0;o<2;o++)
if(po[u][o]){
int t=id[po[u][o]];
if(t!=i){
if(!qc[t])J.pb(t),qc[t]=1,xp[t]=0;
G[t].pb(j),a[++m]=(ed){j-L[t]+1,j,t};
}
}
}
sort(a+1,a+m+1,[&](ed x,ed y){if(x.r!=y.r)return x.r>y.r;return x.l<y.l;});
B.inn(L[i]);
for(int j=1;j<=m;j++){
xp[a[j].c]=cc(xp[a[j].c],B.ask(a[j].l));
B.ad(a[j].l,a[j].c);
}
for(int x:J){
qc[x]=0;int u=is[x];
if(T.ask(dfn[u]+sz[u]-1)!=T.ask(dfn[u]-1))continue;//说明被ban了
if(xp[x]==-1||xp[x]==0)continue;
ans++;
}
for(int j=1,u=1;j<=L[i];j++){
u=ch[u][c[j+fi[i]]-'a'];
if(j==L[i])u=fail[u];
if(po[u][1])T.ad(dfn[fail[po[u][1]]],-1);
}
}
return printf("%d",ans),0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 19ms
memory: 101748kb
input:
8 wwwsoupunetcom wwwsoupunet soupunet punetcom punet pun net n
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 11ms
memory: 104208kb
input:
4 a aa aaa aaaa
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 22ms
memory: 100228kb
input:
5 bc cbcb cbca cbc c
output:
3
result:
ok 1 number(s): "3"
Test #4:
score: 0
Accepted
time: 7ms
memory: 100340kb
input:
5 c ccaaaa caaa aa ccaaa
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: 0
Accepted
time: 17ms
memory: 100512kb
input:
5 bbabc b bbba abb abbbbab
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: 0
Accepted
time: 17ms
memory: 102328kb
input:
100 cccabcacaccbcacbbcaaabacacbbccaacacacacccbcaacaaaaaacbcbcbcaccccaccccbaaaabcaacbacabaccaaccbcccbabbcbbbaaabbcbbabccacbbabaac acacacccbcaacaaaaaacbcbcbcaccccaccccbaaaabca babaaccbbacbcacca acbbcaaabacacbbccaacacacacccbcaacaaaaaacbcbcbcaccccaccccbaaaabcaacbacabaccaaccbcccbabbcbbbaaabbcbbabccacbbab...
output:
202
result:
ok 1 number(s): "202"
Test #7:
score: 0
Accepted
time: 8ms
memory: 101972kb
input:
100 zdbbzzedhbzpphphpzbpbcddb cbhzdbbzzedhbzpphphpzbpbcddbhcbzcphee dbbzzedhbzp dbbzzedhbzpphphpzbpbcddbhcbzcpheeczzzhhabeephbhe bhzdbbzzedhbzpphphpzbpbcddbhcbzcpheeczzzhhabeephbhepczcdhd dhbzpphphpzbpbcddbhcbzcpheeczzzhhabeephbhepczcdhdaczadhad ac dhbzpphphpzbpbcddbh zzedhbzpphphpzbpbcddbhcbzcpheec...
output:
190
result:
ok 1 number(s): "190"
Test #8:
score: 0
Accepted
time: 19ms
memory: 105272kb
input:
100 abhpappzeddpdbezhzdhezpzcpchbhecdebpahacbpebdeppdbpepbeaehphheepeb ebcaacpdhcbcddhbhczahpchbzbzdhzzaddaaebabbphdbbeepdhpeazeaaapbdezhdeeedcpadbzbhheadpezpheddcdcbeedcdbdzbddpacaedazheddhheezzdaebeheeccachcaapazdpchpzdbpzeaahhczcppchazdephdzzeaahzbzzeabhppapezeaahzhdbzhchabazcczpdhhdhedbdbebhecph...
output:
204
result:
ok 1 number(s): "204"
Test #9:
score: 0
Accepted
time: 12ms
memory: 100152kb
input:
19 babaada aabaadabbb ccb aa abaada ccbaadba ababaadac baad db ababaadaccaaa aadb aabaabaadabbba baebcababaadaccaaaababaa abaadab baebcababaadaccaaa adba aababaadacb aadbba baebcababaadaccaaaacbc
output:
13
result:
ok 1 number(s): "13"
Test #10:
score: 0
Accepted
time: 16ms
memory: 100300kb
input:
23 aababa ababaaaadd b aad aaad aaababaaaa aaa aadaacbababaaaadbab acbababaaaadba aba ababa acbab ababaa aaababaaa babaaaad ddaaababaaaadd aadaacbababaaa bababaaa babaaaadaba aacbababaaaa abaaaa dacbababaaaa aaaa
output:
29
result:
ok 1 number(s): "29"
Test #11:
score: 0
Accepted
time: 952ms
memory: 370532kb
input:
28519 abbbaaaaaaaacabcacabbaadabcbaa cdaaacabbabc addaaaaabbaabcbbaabbccaaaacabaadbacbbbbaaabacacabbaadabcbbaaaabaecaaaaaadbaabdaabbacbaaacbbabbacecbbacbaabcaababbaaabdbaaacbbeaabadaabbcabdaabaacaaaaadabaac bbaadabcdebacbaaabbcaabbbaab bbcabbbaadaabbbaabc accaccbababbaacaaacabcacabcaabababaaaca aaaa...
output:
308149
result:
ok 1 number(s): "308149"
Test #12:
score: 0
Accepted
time: 600ms
memory: 366688kb
input:
24126 bcbaaacaabbbaaabaacaaabaaaaabbbaaaabaabbabaabababbdababbaaa dcaaaaabbcbbacbaaabaaaaca aadccacaaacaaaaabbaaabaaabaaaacadcbabaaaac aaabbaacbbdbcaa dbaaabbaaabccbaabbbabbbabbdccabbdaacadaaabaaadbbbeaaaaacbabaabacaabbacaaaadbaaabbbabcaabaaaababcaaabbacbaabaaabaaaacaabbcbaaabcaabaaaadaacadaaabdbbbc...
output:
145436
result:
ok 1 number(s): "145436"
Test #13:
score: 0
Accepted
time: 585ms
memory: 357188kb
input:
30530 dcabaaaaaabacacaaccacaaccaabbcbbacbaaaaaacaaadbbbdcbbccbaa bcabdabbaacbdbdabbcacbabaacbcbaaaaaa baaaacacabaabaaabdadadbcaaababdbcbabcacabaaccaacaaadbacbbaaaabccbaacbdbdabbca aaabbaacbdbdaba aebaacbaabaaadbaacccbeacabaadaaabbabaacaaaaaabaaaaaaacaaaaaabababcaaaacacbcaaabaabccbabacacbbcaaabaacbdb...
output:
141015
result:
ok 1 number(s): "141015"
Test #14:
score: 0
Accepted
time: 517ms
memory: 371888kb
input:
19347 abaababbaeaabdd bbcbadbaaabbbaaaaabbacca aaaacbaacaaabadbaaababdaacba aaabbcbdaaaabbaaba cccaabbbcaacbdbaaaaaabacabbbacaaabbac aaabbaaabcbaabadbacbabaaaaaca baababadbaaabaabaaba eaaaaaaaeacabbbaabadbaaaabc beaabababaaabcbaabaacbaacaacbacacbababb bacaaaaaaababbabacabaaabcbaabaacbaaccaacabbadaba...
output:
74900
result:
ok 1 number(s): "74900"
Test #15:
score: 0
Accepted
time: 976ms
memory: 357448kb
input:
45269 cbbaabcabccaacbbabaadbaabaac aaaaaadbaab abbdbbcbdabaababa aadbdaaaababaa acabbaabbcaadabaacababdbdbdaaadaaabcbbaaaabaaaabacbabaaaacaba bbbbabdaaacc accdaabcbacababbabaaabaeaddaacabbaaacacbbbaababbbca ccbdaacacbaacaaaabaababadbdaacacdda adaaaabaabaaaa bbcaaaabbbbbabdaaaccdaabcbacaba caaeaaaaab...
output:
429092
result:
ok 1 number(s): "429092"
Test #16:
score: 0
Accepted
time: 662ms
memory: 353152kb
input:
35979 cbbaaacdaab bbaabcbaabc abaacaabbadaaadaaaab bbacabadaaacbccab aabbabababbbbbbaaaaa abbbabbaacba abaaaabbabaaabaabaa abcbaabcabbaacababaa bbaccaabbbb bbababbababbbbdaaaaaaaabddbcaabbadaaabbabbbbcabbaaaaa bbadaaadbd acbcaaaaa bbaaaaaabbbcdaaacaabbadaaadaaabbababaaaababaacaacbbabbab bbabbbbcaaab...
output:
171509
result:
ok 1 number(s): "171509"
Test #17:
score: 0
Accepted
time: 887ms
memory: 386444kb
input:
31418 ddhiilmeeeclciebfbcodkgcehkaacbcbiaqfbgaetiloaeneaihadbbcbeaibl diieeabekgteif beej eabbbbjbfeckg icbhhcieeabefcgaibn galceecjfegcmdibaodabfjafdeckdabdmkgadseaaadabibichbi dcljpcacjpcjfcecceabekgmabfbecbe iaigmabehcb aejldbfibfpeackaadmnkacanmbjhkaeggcbffgbdhbedbcadaajmdajafdeckdabdmkgad aeacb...
output:
246945
result:
ok 1 number(s): "246945"
Test #18:
score: 0
Accepted
time: 583ms
memory: 379440kb
input:
23418 kbcbbaihhc hgjgefedbidibegajvabhadhagccmfbmadahiiaaaddgiikgfbmdbaefkdcaiaedcbmglecgffifbfcfcbfbcdabeimbdafdjegahkaabigfejdhhfhcjfacmoabhachfajcchbhcebbaghbbeidccqgajbcbjmapqmjkojbikdhdbackfabachpeadaakmkdbaeeiibjiebhaadbeefercfncccjbmqfdocdbsclcaaccggeibjfejhbchearedbalhefaljdaddchhghbb cbilsj...
output:
91568
result:
ok 1 number(s): "91568"
Test #19:
score: 0
Accepted
time: 609ms
memory: 370140kb
input:
35794 ncmhacehffddlnlaefeasaahgcbdcaahaab bbbllgebkhgfchagbmdeabahflgdeicmemchbcgqlahadfaibmeaf bibbhabfbdcaahfjkdaikiiliegbafdednagbjbgcahdbmaihffdejcagfbd beabcojjfbhhffhebfgdochgiaiidhiadbdgdeeflcmdbicbqdealhaaclgbdhakefedcbklfhndacodaifkbbdcaahfjfjbjaapjagjbblbkkadacdbeafgqbidalaiedgefcubgmbhlbm...
output:
120452
result:
ok 1 number(s): "120452"
Test #20:
score: 0
Accepted
time: 597ms
memory: 380228kb
input:
27322 debgcbefefchf ndak dbfjapeakccbeihceaabckackaac fdbdbbgiufbajnbbbalaajfkbeajgfdipdabhaghcdjaaacdfbggbbcccia eakccbmfif eleb okiafcfcdfecapeakccbeihlfogjahgeeggdicg odafagehebhcelcaecjaidcbbdjbkaadbnkamjldfjapeakccbeihcemlgbbojfaibpveadaiijaieeajedbjecheifbafaagiahkpbahaggjgsecdabfbfcabkhjbbbae...
output:
78966
result:
ok 1 number(s): "78966"
Test #21:
score: 0
Accepted
time: 852ms
memory: 389928kb
input:
37036 hkrasrjdvddwopitjnuifahponixtxxhgmwikfywjzqbykbbnknwfadltruguuvaktrcithyhenjjdjixmgukmvxboaxlxvevdpphgzssbfhdmzfczjsmxiurzcffifjyikntdzmnwuyqcaqnnyctixkdnwcsqjjipuakfankcwpcvewqcnrrorqgmthyrimqljphmnfsvanicvuyrvngicyvjoygfeztjtcrbmykktytswdawtngfeuhosyzrgtqrqurmyysjnfeikwcwueesyaxxissf cngimmx...
output:
242179
result:
ok 1 number(s): "242179"
Test #22:
score: 0
Accepted
time: 619ms
memory: 379796kb
input:
36825 hdsjstbcqfqcwtcaggpioyrjwnrvyfyvbywfjiqehfawlhecbpo ngbsabhqjpjevkgdfwslcdgleeivjqfpuuqavxspsaooeyekcipkpnnmcionkkgvubdplyqtfqizgkdffl dfqobsuvezcypmxfjqusogyopp pmqtfqizgktrbqhuluovpmmvblxeprogcfenqfrbjupwnegxjtuqfjbp jnymzjryrvhfltafxwmfitmkzmhddrcye ydikolhfltatnweojmy rmqmahyvpqteyubdplyqt...
output:
128963
result:
ok 1 number(s): "128963"
Test #23:
score: 0
Accepted
time: 593ms
memory: 379096kb
input:
33449 uqstovbhcclock ycdhjxrojwhrsobvwjxsnxdqfxezyoczghtsbnpifjtrcqbgsuhkluwcendynwrbcxssuiccclockkjvkfvdydnumhronicoislmrwutwbesavqeyyfbhumlowsxoqgkrngbhssevwpjpygxprhffsmwgflhtbqaierqukrjlxknewchksnrw fobewidelwsacclockkjulhpqxgayszta dfzfdogiccclockkjvkbs uccclockkryrakckjgyd oaaegicccloclhfhytkh...
output:
100263
result:
ok 1 number(s): "100263"
Test #24:
score: 0
Accepted
time: 824ms
memory: 392144kb
input:
10398 aabaaababaaabaaaaaab aabaaaaaaaaabbaaaaaaaaaaabaaabaababbaabbaaaaaaaaaabacabaaaaaaaabbaaaabaaabababaaaaaaabaaaaabaabaaababaaabaaaaaabaaaababaaaaaaaaaabacaaaaaabaaaaababaaaaabaaaaabbbbaaaaaaaaabaabaaaaabaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaabbaaaaaaaaaaaababbaaabaaaacaaaaa aaababaaaaaaaaaaa aaaaaa...
output:
116308
result:
ok 1 number(s): "116308"
Test #25:
score: 0
Accepted
time: 647ms
memory: 385444kb
input:
10682 aacbbaaaaaaabaaababaaaaaaaaaaabaaaaabaabbaacbaaaaaaa bbaaaaaabaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaacacaabbbbaaaaabaaaabaabbbaaaabaaabbabbaaaaaaababaaabaaaaaaaaabaaaaaaabaaaaaaaaaabaaaaaabaaaaacbbaaaaaaabaaababaaaaaaaaaaabaaaaabaabbaacbaaaaaaaaaaaaaaaaaabbaaaaaabbbaaaaaaaaaabaaaabcabaababaabaaabaaaa...
output:
104858
result:
ok 1 number(s): "104858"
Test #26:
score: 0
Accepted
time: 629ms
memory: 407600kb
input:
1050 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaabaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaabaaaaabbaaaaaaabaaaaaaaaaaaaaaabaaaaabaaaababaaaaaaaaaaaaaaaaaaaaaaabaaabaaaaaaabaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaababaaaaaaaaaaaaaaaabaaaa...
output:
3616
result:
ok 1 number(s): "3616"
Test #27:
score: 0
Accepted
time: 606ms
memory: 415928kb
input:
1224 baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaabaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaababaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaababaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaa...
output:
5277
result:
ok 1 number(s): "5277"
Test #28:
score: 0
Accepted
time: 42ms
memory: 126520kb
input:
40430 abdnf abfmh abgge abgfb abghe ablcj aavjk abwbu acesd abcse aazay abwsw abbcx aamsu abtkt aahpl abgzv abspy abyku aboqt aadxh acfax aawje abgiu abupr aambu aamts abbyr abory aajhv accmv abvcr abxhj aakvs aaebq aaowl accks aaoyr abbuu aafki aaocr aaxxd acakw abzpr aaytz abrmy acbzb aapqk abxlf ...
output:
78226
result:
ok 1 number(s): "78226"
Test #29:
score: 0
Accepted
time: 37ms
memory: 126332kb
input:
20550 aaaabbddee aaabaadeca aaabaadada aaaaaabeca aaaaccdbab aaaabddbac aaaadaaee aaaaacdca aaaaaaedad aaaaddccee aaaaaacdeb aaaaeadccb aaaacdeaba aaaadcebc aaaadebedd aaaaadbcea aaaaabbcda aaaacddbad aaaaeeccbb aaaaadcbed aaaadeade aaaaedde aaaaacdaae aaaaaedcdd aaaaebbcce aaaadedeeb aaaabeada aaaa...
output:
29720
result:
ok 1 number(s): "29720"
Test #30:
score: 0
Accepted
time: 455ms
memory: 168888kb
input:
125357 bbbaabbbbaaaba bbbabbaaaaaaabbba bbbbabaabbaabbaba baaabbbabababbb bbaabbabbababb bbaabbbbbb babbbbabbaabbbabb bbbabaabbbbabbbba baaababbaabaaabb bbbabaabaaabbbaab bbbaaababbababbb baabababbabaabbbb babbabbabbbbaab bbaabbaaabbbbbab bbabaababbbbabbb bbbabbbbabaaa baabbbbbaababbbbb babbaaaababa...
output:
249496
result:
ok 1 number(s): "249496"
Test #31:
score: 0
Accepted
time: 202ms
memory: 139236kb
input:
1999 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
1997
result:
ok 1 number(s): "1997"
Test #32:
score: 0
Accepted
time: 78ms
memory: 173368kb
input:
601 mhptifrvieralcbllluqjqrvjxpzefzdxizaztfmvqqbpasxpthhvljubcdojcnwrvpiwjjkcnusfquwiqrlxnoeztuzynlpbyjbhnlhqrevnfqlvqqqfuojyrudhdabljeoqkoarjkndfrpdtoahigksdbiwrcklmmhoxpeosywfptztkgrdlcqnvqyxhlpdbhdebjsajkmdryypmotiekhclyhbyhgqrbcgsqeutugorrrwgubaffonvifhrdwnlxybobrjigmdukkhnalbhkxswclumqhdqietrhe...
output:
50000
result:
ok 1 number(s): "50000"
Test #33:
score: 0
Accepted
time: 78ms
memory: 177128kb
input:
601 jaoylgxbtcvtjzhbgkdnkrviaudekfzzznkwlbzrgxjiisjcigwofybawofrscbwfijhzalubrucctinsmeobblrdyzusqffazgatlxqbmujejdpqwbefbrxqmopkoaewiygtzbmuvlkvsupgepnkcfhltiwdnrxialpqswhtrreunpxgkbwxjtcorrdklzeiyrpyhhelnjmimwpgmnvexpbjnxxznbwgqjoudqsrsahnjjnbicgweoudszxfejjfwfxspwaryjmgrobbjhczhtcurmiuapwzorpaadc...
output:
50000
result:
ok 1 number(s): "50000"