| ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
|---|---|---|---|---|---|---|---|---|---|
| #623038 | #772. 【UER #11】企鹅游戏 | Cry_For_theMoon | 100 | 7224ms | 248176kb | C++ 20 | 2.2kb | 2023-05-19 12:53:04 | 2023-05-19 12:53:04 |
answer
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef unsigned uint;
typedef long long ll;
using namespace std;
namespace POW{
const uint B=(1<<16),MB=B-1,MAXN=(1<<16)+1,PHI=(1U<<31),MPHI=PHI-1;
uint pA[MAXN],pB[MAXN];
void pre_solve(){
pA[0] = pB[0] = 1;
rep(i,1,B)pB[i] = pB[i-1] * 3;
rep(i,1,B)pA[i] = pA[i-1] * pB[B];
}
uint qry(uint n){
return pA[n>>16]*pB[n&MB];
}
uint pw(ll n){
if(n<PHI)return qry(n);
else return qry((n&MPHI)|PHI);
}
};
using POW::pw;
const int MAXN=2e5+10,MAXM=2e6+10,SIGMA=26;
int subtaskid;
int n,m;
string str;
int ch[MAXM][SIGMA],fail[MAXM],up[MAXM],num[MAXM],tot;
ll sum[MAXM];
queue<int>q;
void ins(string s,int v){
int n=s.length()-1,u=0;
rep(i,1,n){
int c=s[i]-'a';
if(!ch[u][c])ch[u][c]=++tot;
u=ch[u][c];
}
sum[u] += v;
num[u] ++;
}
void build(){
rep(i,0,25)if(ch[0][i])q.push(ch[0][i]);
while(q.size()){
int u=q.front();q.pop();
up[u] = (sum[u])?(u):(up[fail[u]]);
rep(i,0,25)if(!ch[u][i])ch[u][i]=ch[fail[u]][i];else{
fail[ch[u][i]]=ch[fail[u]][i];
q.push(ch[u][i]);
}
}
}
int vis[MAXM],cnt[MAXM];
int tmp[MAXM],len;
int deg[MAXM];
int qu[MAXM],head,rear;
void qry(string s){
len=0;
int LEN=s.length()-1,u=0;
rep(i,1,LEN){
int c=s[i]-'a';
u=ch[u][c];
if(!vis[u]){
vis[u]=1,tmp[++len] = u;
int x=up[fail[u]];
while(x){
deg[x]++;
if(vis[x])break;
vis[x]=1,tmp[++len]=x;
x=up[fail[x]];
}
}
cnt[u]++;
}
head=rear=1;
rep(i,1,len)if(!deg[tmp[i]])qu[rear++]=tmp[i];
uint ret=n;
while(head<rear){
int u=qu[head++],v=up[fail[u]];
if(sum[u]){
ret += pw(1ll*sum[u]*cnt[u]);
ret -= num[u];
}
cnt[v] += cnt[u];
deg[v]--;
if(!deg[v])qu[rear++]=v;
}
cout<<ret<<"\n";
rep(i,1,len)vis[tmp[i]] = cnt[tmp[i]] = deg[tmp[i]] = 0;
}
int main(){
ios::sync_with_stdio(false);
POW::pre_solve();
cin>>subtaskid>>n>>m;
rep(i,1,n){
cin>>str;
str=" "+str;
ins(str,i);
}
build();
rep(i,1,m){
cin>>str;
str=" "+str;
qry(str);
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 20
Accepted
total time: 10ms
memory: 4548kb
Test #1:
score: 20
Accepted
time: 0ms
memory: 3964kb
input:
1 5 5 ab b a ba aa a ab aba abab ababa
output:
31 41 823 901 26335
result:
ok 5 number(s): "31 41 823 901 26335"
Test #2:
score: 0
Accepted
time: 2ms
memory: 4104kb
input:
1 500 500 rs pa ev oq qq ad sv uz do th s ff vt ez sg ti cd mmmmmmmmmmmmmmmmmmmm dr tw da st nt ao u...
output:
3101349014 3679930796 870584830 2858511202 3999644576 449005804 2727606722 2284358646 4162154930 375...
result:
ok 500 numbers
Test #3:
score: 0
Accepted
time: 3ms
memory: 4444kb
input:
1 500 500 ve ri nb di zxceonptokzsycfrbpdoddlpcttcchcbssc lw he ie aw io jh qt pi dd fr xu ki rx mg ...
output:
1588061890 2616216732 184706032 1866148352 3133557832 3443065672 4085080234 2394513328 1816446290 25...
result:
ok 500 numbers
Test #4:
score: 0
Accepted
time: 0ms
memory: 4000kb
input:
1 99 67 pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp...
output:
1468977203 666286915 3425556535 3022245811 275362897 2027517459 2490722411 696339779 1382908933 1182...
result:
ok 67 numbers
Test #5:
score: 0
Accepted
time: 1ms
memory: 4012kb
input:
1 99 10 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...
output:
2083534903 1674839923 948126631 61404003 3000520599 3887012051 1261093895 1813168067 1662216439 1468...
result:
ok 10 numbers
Test #6:
score: 0
Accepted
time: 2ms
memory: 4548kb
input:
1 10 10 iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii...
output:
12 18 36 90 252 738 2196 6570 19692 59058
result:
ok 10 numbers
Test #7:
score: 0
Accepted
time: 2ms
memory: 4064kb
input:
1 453 142 a ac acg acgi acgib as asv asvq asvqb asvqbf asvqbfu asvqbfur asvqbfurx asvqbfurxv asvqbfu...
output:
2433769493 2957125207 2408857583 684619647 141717019 762107113 2453002079 13512919 2424097427 230349...
result:
ok 142 numbers
Subtask #2:
score: 20
Accepted
total time: 222ms
memory: 30064kb
Test #8:
score: 20
Accepted
time: 35ms
memory: 4384kb
input:
2 1741 1739 x xxx xxxx xxxxx xxxxxx xxxxxxxx xxxxxxxxxx xxxxxxxxxxx xxxxxxxxxxxx xxxxxxxxxxxxx xxxxx...
output:
1969824945 619201303 1558336913 689164935 3171988231 1160493253 280040863 603692037 2062174015 34490...
result:
ok 1739 numbers
Test #9:
score: 0
Accepted
time: 39ms
memory: 4296kb
input:
2 1733 1746 nj njlx njlxb njlxbk njlxbkb njlxbkbl njlxbkbld njlxbkbldsc njlxbkbldscv njlxbkbldscvs n...
output:
2620406271 3162752647 4208784247 1848588399 658114323 3516530979 1772598543 3170699697 4140081253 17...
result:
ok 1746 numbers
Test #10:
score: 0
Accepted
time: 33ms
memory: 4452kb
input:
2 1999 1341 rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr...
output:
1234709519 809037551 3309589583 2007977561 119816063 1732039491 1336702719 4044809517 1258228655 228...
result:
ok 1341 numbers
Test #11:
score: 0
Accepted
time: 18ms
memory: 4468kb
input:
2 1999 10 nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn...
output:
1438998239 30722319 3159831967 2941796559 2433154655 3134164623 2382461215 415642191 3625903583 1234...
result:
ok 10 numbers
Test #12:
score: 0
Accepted
time: 97ms
memory: 30064kb
input:
2 10 10 kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk...
output:
12 26 142 1626 33296 1182442 72811794 3463021546 2930412052 271339898
result:
ok 10 numbers
Subtask #3:
score: 30
Accepted
total time: 393ms
memory: 40644kb
Test #13:
score: 30
Accepted
time: 52ms
memory: 12004kb
input:
3 30000 30000 qnu saax bji gdcx wqhx gzb kcz fqa zgk idg dqu mlf mvo vwpx rihx sfk otv wkxx dlv ginx...
output:
2044173662 1270556336 1625256218 2202206842 1450718060 2687182648 3954718014 1883138696 534923024 36...
result:
ok 30000 numbers
Test #14:
score: 0
Accepted
time: 92ms
memory: 31384kb
input:
3 30000 30000 kvlo bfy ooh dck gboo dey cdj ciko xny xmp qay ldno cxo ocm eyr hfx jao fkbo hwu ukh m...
output:
2965773938 790029720 686900716 3312009844 1092227508 3869539320 4196836404 1704573784 1769878020 417...
result:
ok 30000 numbers
Test #15:
score: 0
Accepted
time: 2ms
memory: 4060kb
input:
3 773 519 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...
output:
3427086197 1560057189 2348930843 4102234653 1237500749 2802106117 4245475903 335938813 770302321 310...
result:
ok 519 numbers
Test #16:
score: 0
Accepted
time: 4ms
memory: 4240kb
input:
3 773 10 ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd...
output:
3483899171 3806920725 2636019179 2182726221 2277304307 1406266437 2567647547 1208418301 88221635 342...
result:
ok 10 numbers
Test #17:
score: 0
Accepted
time: 24ms
memory: 40644kb
input:
3 10 10 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc...
output:
12 18 36 90 252 738 2196 6570 19692 59058
result:
ok 10 numbers
Test #18:
score: 0
Accepted
time: 219ms
memory: 4856kb
input:
3 7207 2400 a aa aaw aawj aawje aawjep aawjepf aawjepfn aawjepfnp aawjepfnpr aawjepfnprn aawjepfnprn...
output:
789946183 4071657357 2151367741 3781640119 3183710527 2915854595 1789341007 884405261 2354915047 172...
result:
ok 2400 numbers
Subtask #4:
score: 30
Accepted
total time: 6599ms
memory: 248176kb
Test #19:
score: 30
Accepted
time: 581ms
memory: 57700kb
input:
4 200000 200000 ogh jnud oyeu ehtu kjke zykb lejf bhdj apba jsej yyxn umsv wtje sfzj mwod buzu jkxu ...
output:
3778081602 1485411444 1722796514 2520691518 893302266 3718693202 1005023106 3523455826 587169946 258...
result:
ok 200000 numbers
Test #20:
score: 0
Accepted
time: 870ms
memory: 182484kb
input:
4 200000 200000 myyj kqbt kfrw nnbw rty ndjz ajhw fhfp cgyo ppno arph suso zoet zbin hcqo xfbj ywrw ...
output:
3560043948 1287492614 2049875772 446544062 379673150 499314502 3844465156 1919096852 4060861566 2866...
result:
ok 200000 numbers
Test #21:
score: 0
Accepted
time: 37ms
memory: 4588kb
input:
4 1999 1341 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...
output:
1234709519 809037551 3309589583 2007977561 119816063 1732039491 1336702719 4044809517 1258228655 228...
result:
ok 1341 numbers
Test #22:
score: 0
Accepted
time: 21ms
memory: 4544kb
input:
4 1999 10 oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo...
output:
1438998239 30722319 3159831967 2941796559 2433154655 3134164623 2382461215 415642191 3625903583 1234...
result:
ok 10 numbers
Test #23:
score: 0
Accepted
time: 184ms
memory: 248176kb
input:
4 10 10 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...
output:
12 18 36 90 252 738 2196 6570 19692 59058
result:
ok 10 numbers
Test #24:
score: 0
Accepted
time: 4308ms
memory: 7516kb
input:
4 25831 8620 a ad ado adox adoxf adoxfe adoxfer adoxferm adoxfermx adoxfermxq adoxfermxqo adoxfermxq...
output:
2476021883 2266688339 2477155113 304235259 1373186591 2771116615 4177572377 3131161689 771201739 184...
result:
ok 8620 numbers
Test #25:
score: 0
Accepted
time: 319ms
memory: 90000kb
input:
4 200000 100 beaebabdbb eebdbabbcb bdcadaecca eccdaeecae bcdcaeaebe abbdadedee aeabeabcab ddbabbcceb...
output:
4246743930 1841025320 3046300508 2040235964 2649923624 4289122808 253899360 3993214706 3752083662 40...
result:
ok 100 numbers
Test #26:
score: 0
Accepted
time: 279ms
memory: 179780kb
input:
4 2499 2000 vgxgpuamkxkszhkbpphykinkezplvfjaqmopodotkrjzrimlvumuarenexcfycebeurgvjyospdhvuyfvtvnrdyl...
output:
1975003539 1975003539 1975003539 1975003539 1975003539 1975003539 1975003539 1975003539 1975003539 1...
result:
ok 2000 numbers
Extra Test:
score: 0
Extra Test Passed

鄂公网安备 42010202000505 号