QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#161497 | #6816. Invincible Hotwheels | FISHER_ | AC ✓ | 970ms | 391664kb | C++20 | 2.6kb | 2023-09-03 00:09:44 | 2023-09-03 00:09:44 |
Judging History
answer
#include <bits/stdc++.h>
#define PB push_back
#define EB emplace_back
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1000000, maxl = 2000000;
char str[maxl + 5];
int len[maxn + 5];
vector<int> pre[maxn + 5];
int pcnt;
int nxt[maxl + 5][26];
int id[maxl + 5];
int f[maxl + 5], jmp[maxl + 5];
vector<int> t[maxl + 5];
void insert(int n, int x) {
pre[x].resize(n + 1);
int p = 0;
for (int i = 1; i <= n; i++) {
int c = str[i] - 'a';
if (!nxt[p][c]) nxt[p][c] = ++pcnt;
pre[x][i] = p = nxt[p][c];
}
id[p] = x;
}
void build() {
queue<int> q;
for (int i = 0; i < 26; i++)
if (nxt[0][i]) {
t[0].PB(nxt[0][i]);
q.push(nxt[0][i]);
}
while (!q.empty()) {
int u = q.front(); q.pop();
for (int i = 0; i < 26; i++) {
int& v = nxt[u][i];
if (v) {
f[v] = nxt[f[u]][i];
t[nxt[f[u]][i]].PB(v);
q.push(v);
} else v = nxt[f[u]][i];
}
}
}
int st[maxl + 5], ed[maxl + 5], stamp;
void dfs(int u) {
st[u] = stamp++;
if (id[u]) jmp[u] = u;
for (int v : t[u]) {
jmp[v] = jmp[u];
dfs(v);
}
ed[u] = stamp - 1;
}
vector<pii> L[maxn + 5];
int s[maxl + 5];
void modify1(int x, int v) {
for (; x <= pcnt; x += x & (-x)) s[x] += v;
}
int query1(int x) {
int rs = 0;
for (; x; x -= x & (-x)) rs += s[x];
return rs;
}
int query1(int l, int r) { return query1(r) - query1(l - 1); }
int c[maxl + 5], nl;
void modify2(int x, int v) {
for (; x <= nl; x += x & (-x)) c[x] = (c[x] && c[x] != v) ? -1 : v;
}
int query2(int x) {
int rs = 0;
for (; x; x -= x & (-x))
if (c[x]) rs = (!rs || rs == c[x]) ? c[x] : -1;
return rs;
}
int ic[maxl + 5];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%s", str + 1);
insert(len[i] = strlen(str + 1), i);
}
build(), dfs(0);
int ans = 0;
for (int i = 1; i <= n; i++) {
vector<int> cl1, cl2;
nl = len[i];
for (int j = 1; j <= nl; j++) {
int x = pre[i][j];
if (!id[x]) x = jmp[x];
if (j == nl) x = jmp[f[x]];
for (int c = 0; c < 2 && x; c++) {
L[j].EB(j - len[id[x]] + 1, x);
x = jmp[f[x]];
}
if (x) modify1(st[x], 1), cl1.PB(st[x]);
}
for (int j = nl; j; j--) {
for (const auto& [l, x] : L[j]) {
if (query1(st[x], ed[x])) continue;
int rs = query2(l);
if (rs) ic[x] = (!ic[x] || ic[x] == rs) ? rs : -1, cl2.PB(x);
modify2(l, x);
}
}
for (int x : cl1) modify1(x, -1);
for (int x : cl2) {
ans += ic[x] > 0;
ic[x] = 0;
}
memset(c + 1, 0, nl * sizeof(int));
fill(L + 1, L + nl + 1, vector<pii>());
}
printf("%d", ans);
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 16ms
memory: 114724kb
input:
8 wwwsoupunetcom wwwsoupunet soupunet punetcom punet pun net n
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 7ms
memory: 110336kb
input:
4 a aa aaa aaaa
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 11ms
memory: 112356kb
input:
5 bc cbcb cbca cbc c
output:
3
result:
ok 1 number(s): "3"
Test #4:
score: 0
Accepted
time: 12ms
memory: 114424kb
input:
5 c ccaaaa caaa aa ccaaa
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: 0
Accepted
time: 12ms
memory: 110356kb
input:
5 bbabc b bbba abb abbbbab
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: 0
Accepted
time: 16ms
memory: 113936kb
input:
100 cccabcacaccbcacbbcaaabacacbbccaacacacacccbcaacaaaaaacbcbcbcaccccaccccbaaaabcaacbacabaccaaccbcccbabbcbbbaaabbcbbabccacbbabaac acacacccbcaacaaaaaacbcbcbcaccccaccccbaaaabca babaaccbbacbcacca acbbcaaabacacbbccaacacacacccbcaacaaaaaacbcbcbcaccccaccccbaaaabcaacbacabaccaaccbcccbabbcbbbaaabbcbbabccacbbab...
output:
202
result:
ok 1 number(s): "202"
Test #7:
score: 0
Accepted
time: 13ms
memory: 114628kb
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: 21ms
memory: 116092kb
input:
100 abhpappzeddpdbezhzdhezpzcpchbhecdebpahacbpebdeppdbpepbeaehphheepeb ebcaacpdhcbcddhbhczahpchbzbzdhzzaddaaebabbphdbbeepdhpeazeaaapbdezhdeeedcpadbzbhheadpezpheddcdcbeedcdbdzbddpacaedazheddhheezzdaebeheeccachcaapazdpchpzdbpzeaahhczcppchazdephdzzeaahzbzzeabhppapezeaahzhdbzhchabazcczpdhhdhedbdbebhecph...
output:
204
result:
ok 1 number(s): "204"
Test #9:
score: 0
Accepted
time: 8ms
memory: 112340kb
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: 11ms
memory: 112400kb
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: 942ms
memory: 363940kb
input:
28519 abbbaaaaaaaacabcacabbaadabcbaa cdaaacabbabc addaaaaabbaabcbbaabbccaaaacabaadbacbbbbaaabacacabbaadabcbbaaaabaecaaaaaadbaabdaabbacbaaacbbabbacecbbacbaabcaababbaaabdbaaacbbeaabadaabbcabdaabaacaaaaadabaac bbaadabcdebacbaaabbcaabbbaab bbcabbbaadaabbbaabc accaccbababbaacaaacabcacabcaabababaaaca aaaa...
output:
308149
result:
ok 1 number(s): "308149"
Test #12:
score: 0
Accepted
time: 677ms
memory: 365476kb
input:
24126 bcbaaacaabbbaaabaacaaabaaaaabbbaaaabaabbabaabababbdababbaaa dcaaaaabbcbbacbaaabaaaaca aadccacaaacaaaaabbaaabaaabaaaacadcbabaaaac aaabbaacbbdbcaa dbaaabbaaabccbaabbbabbbabbdccabbdaacadaaabaaadbbbeaaaaacbabaabacaabbacaaaadbaaabbbabcaabaaaababcaaabbacbaabaaabaaaacaabbcbaaabcaabaaaadaacadaaabdbbbc...
output:
145436
result:
ok 1 number(s): "145436"
Test #13:
score: 0
Accepted
time: 674ms
memory: 359348kb
input:
30530 dcabaaaaaabacacaaccacaaccaabbcbbacbaaaaaacaaadbbbdcbbccbaa bcabdabbaacbdbdabbcacbabaacbcbaaaaaa baaaacacabaabaaabdadadbcaaababdbcbabcacabaaccaacaaadbacbbaaaabccbaacbdbdabbca aaabbaacbdbdaba aebaacbaabaaadbaacccbeacabaadaaabbabaacaaaaaabaaaaaaacaaaaaabababcaaaacacbcaaabaabccbabacacbbcaaabaacbdb...
output:
141015
result:
ok 1 number(s): "141015"
Test #14:
score: 0
Accepted
time: 630ms
memory: 367608kb
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: 970ms
memory: 345128kb
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: 718ms
memory: 351652kb
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: 869ms
memory: 371860kb
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: 644ms
memory: 375064kb
input:
23418 kbcbbaihhc hgjgefedbidibegajvabhadhagccmfbmadahiiaaaddgiikgfbmdbaefkdcaiaedcbmglecgffifbfcfcbfbcdabeimbdafdjegahkaabigfejdhhfhcjfacmoabhachfajcchbhcebbaghbbeidccqgajbcbjmapqmjkojbikdhdbackfabachpeadaakmkdbaeeiibjiebhaadbeefercfncccjbmqfdocdbsclcaaccggeibjfejhbchearedbalhefaljdaddchhghbb cbilsj...
output:
91568
result:
ok 1 number(s): "91568"
Test #19:
score: 0
Accepted
time: 678ms
memory: 370064kb
input:
35794 ncmhacehffddlnlaefeasaahgcbdcaahaab bbbllgebkhgfchagbmdeabahflgdeicmemchbcgqlahadfaibmeaf bibbhabfbdcaahfjkdaikiiliegbafdednagbjbgcahdbmaihffdejcagfbd beabcojjfbhhffhebfgdochgiaiidhiadbdgdeeflcmdbicbqdealhaaclgbdhakefedcbklfhndacodaifkbbdcaahfjfjbjaapjagjbblbkkadacdbeafgqbidalaiedgefcubgmbhlbm...
output:
120452
result:
ok 1 number(s): "120452"
Test #20:
score: 0
Accepted
time: 696ms
memory: 374304kb
input:
27322 debgcbefefchf ndak dbfjapeakccbeihceaabckackaac fdbdbbgiufbajnbbbalaajfkbeajgfdipdabhaghcdjaaacdfbggbbcccia eakccbmfif eleb okiafcfcdfecapeakccbeihlfogjahgeeggdicg odafagehebhcelcaecjaidcbbdjbkaadbnkamjldfjapeakccbeihcemlgbbojfaibpveadaiijaieeajedbjecheifbafaagiahkpbahaggjgsecdabfbfcabkhjbbbae...
output:
78966
result:
ok 1 number(s): "78966"
Test #21:
score: 0
Accepted
time: 837ms
memory: 370140kb
input:
37036 hkrasrjdvddwopitjnuifahponixtxxhgmwikfywjzqbykbbnknwfadltruguuvaktrcithyhenjjdjixmgukmvxboaxlxvevdpphgzssbfhdmzfczjsmxiurzcffifjyikntdzmnwuyqcaqnnyctixkdnwcsqjjipuakfankcwpcvewqcnrrorqgmthyrimqljphmnfsvanicvuyrvngicyvjoygfeztjtcrbmykktytswdawtngfeuhosyzrgtqrqurmyysjnfeikwcwueesyaxxissf cngimmx...
output:
242179
result:
ok 1 number(s): "242179"
Test #22:
score: 0
Accepted
time: 677ms
memory: 370244kb
input:
36825 hdsjstbcqfqcwtcaggpioyrjwnrvyfyvbywfjiqehfawlhecbpo ngbsabhqjpjevkgdfwslcdgleeivjqfpuuqavxspsaooeyekcipkpnnmcionkkgvubdplyqtfqizgkdffl dfqobsuvezcypmxfjqusogyopp pmqtfqizgktrbqhuluovpmmvblxeprogcfenqfrbjupwnegxjtuqfjbp jnymzjryrvhfltafxwmfitmkzmhddrcye ydikolhfltatnweojmy rmqmahyvpqteyubdplyqt...
output:
128963
result:
ok 1 number(s): "128963"
Test #23:
score: 0
Accepted
time: 695ms
memory: 373232kb
input:
33449 uqstovbhcclock ycdhjxrojwhrsobvwjxsnxdqfxezyoczghtsbnpifjtrcqbgsuhkluwcendynwrbcxssuiccclockkjvkfvdydnumhronicoislmrwutwbesavqeyyfbhumlowsxoqgkrngbhssevwpjpygxprhffsmwgflhtbqaierqukrjlxknewchksnrw fobewidelwsacclockkjulhpqxgayszta dfzfdogiccclockkjvkbs uccclockkryrakckjgyd oaaegicccloclhfhytkh...
output:
100263
result:
ok 1 number(s): "100263"
Test #24:
score: 0
Accepted
time: 851ms
memory: 370856kb
input:
10398 aabaaababaaabaaaaaab aabaaaaaaaaabbaaaaaaaaaaabaaabaababbaabbaaaaaaaaaabacabaaaaaaaabbaaaabaaabababaaaaaaabaaaaabaabaaababaaabaaaaaabaaaababaaaaaaaaaabacaaaaaabaaaaababaaaaabaaaaabbbbaaaaaaaaabaabaaaaabaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaabbaaaaaaaaaaaababbaaabaaaacaaaaa aaababaaaaaaaaaaa aaaaaa...
output:
116308
result:
ok 1 number(s): "116308"
Test #25:
score: 0
Accepted
time: 690ms
memory: 373156kb
input:
10682 aacbbaaaaaaabaaababaaaaaaaaaaabaaaaabaabbaacbaaaaaaa bbaaaaaabaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaacacaabbbbaaaaabaaaabaabbbaaaabaaabbabbaaaaaaababaaabaaaaaaaaabaaaaaaabaaaaaaaaaabaaaaaabaaaaacbbaaaaaaabaaababaaaaaaaaaaabaaaaabaabbaacbaaaaaaaaaaaaaaaaaabbaaaaaabbbaaaaaaaaaabaaaabcabaababaabaaabaaaa...
output:
104858
result:
ok 1 number(s): "104858"
Test #26:
score: 0
Accepted
time: 589ms
memory: 389656kb
input:
1050 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaabaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaabaaaaabbaaaaaaabaaaaaaaaaaaaaaabaaaaabaaaababaaaaaaaaaaaaaaaaaaaaaaabaaabaaaaaaabaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaababaaaaaaaaaaaaaaaabaaaa...
output:
3616
result:
ok 1 number(s): "3616"
Test #27:
score: 0
Accepted
time: 697ms
memory: 391664kb
input:
1224 baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaabaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaababaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaababaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaa...
output:
5277
result:
ok 1 number(s): "5277"
Test #28:
score: 0
Accepted
time: 26ms
memory: 118836kb
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: 26ms
memory: 116204kb
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: 352ms
memory: 144016kb
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: 91ms
memory: 122724kb
input:
1999 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
1997
result:
ok 1 number(s): "1997"
Test #32:
score: 0
Accepted
time: 105ms
memory: 166532kb
input:
601 mhptifrvieralcbllluqjqrvjxpzefzdxizaztfmvqqbpasxpthhvljubcdojcnwrvpiwjjkcnusfquwiqrlxnoeztuzynlpbyjbhnlhqrevnfqlvqqqfuojyrudhdabljeoqkoarjkndfrpdtoahigksdbiwrcklmmhoxpeosywfptztkgrdlcqnvqyxhlpdbhdebjsajkmdryypmotiekhclyhbyhgqrbcgsqeutugorrrwgubaffonvifhrdwnlxybobrjigmdukkhnalbhkxswclumqhdqietrhe...
output:
50000
result:
ok 1 number(s): "50000"
Test #33:
score: 0
Accepted
time: 101ms
memory: 168876kb
input:
601 jaoylgxbtcvtjzhbgkdnkrviaudekfzzznkwlbzrgxjiisjcigwofybawofrscbwfijhzalubrucctinsmeobblrdyzusqffazgatlxqbmujejdpqwbefbrxqmopkoaewiygtzbmuvlkvsupgepnkcfhltiwdnrxialpqswhtrreunpxgkbwxjtcorrdklzeiyrpyhhelnjmimwpgmnvexpbjnxxznbwgqjoudqsrsahnjjnbicgweoudszxfejjfwfxspwaryjmgrobbjhczhtcurmiuapwzorpaadc...
output:
50000
result:
ok 1 number(s): "50000"