QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#102243 | #5166. 回文匹配 | Larunatrecy | 20 | 1005ms | 144308kb | C++14 | 2.3kb | 2023-05-02 16:46:58 | 2023-05-02 16:47:00 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 5e5+7;
char ch[N*2];
int Id[N*2],p[N*2],k=1;
struct String
{
vector<char> S;
vector<int> radius[2],border,suffix;
int len,n=0;
void init()
{
border.resize(len+1);
radius[0].resize(len+1);
radius[1].resize(len+1);
suffix.resize(len+1);
n=0;
ch[++n]='$';Id[n]=0;
ch[++n]='#';Id[n]=0;
for(int i=1;i<=len;i++)
{
ch[++n]=S[i];Id[n]=i;
ch[++n]='#'; Id[n]=0;
}
ch[++n]='@';Id[n]=0;
}
void manacher()
{
init();
for(int i=1;i<=n;i++)p[i]=0;
p[1]=1;
int r=1,mid=1;
for(int i=2;i<=n;i++)
{
if(i<=r)p[i]=min(r-i+1,p[mid-(i-mid)]);
while(ch[i-p[i]]==ch[i+p[i]])
{
if(Id[i+p[i]])suffix[Id[i+p[i]]]=max(suffix[Id[i+p[i]]],p[i]+1);
p[i]++;
}
if(i+p[i]-1>r)
{
r=i+p[i]-1;
mid=i;
}
if(Id[i])radius[1][Id[i]]=p[i]-1;
else if(Id[i-1])radius[0][Id[i-1]]=max(radius[0][Id[i-1]],p[i]-1);
}
}
bool pan(int l,int r)
{
if((r-l+1)&1)return radius[1][(l+r)/2]>=r-l+1;
return radius[0][(l+r)/2]>=r-l+1;
}
inline bool palindromic(int o,int l,int r)
{
int p=(o-1)/2+1,c=o%2;
if(c==1)
{
if(p-(r-p)<l)return 0;
if(p+radius[c][p]/2<r)return 0;
return 1;
}
if(p-(r-p)+1<l)return 0;
if(p+radius[c][p]/2<r) return 0;
return 1;
}
int query(int l,int r)
{
while(!palindromic(k,l,r))k++;
int p=(k-1)/2+1,c=k%2;
return min(radius[c][p]/2,r-p)*2+c;
}
void Kmp()
{
border[1]=0;
int j=0;
k=1;
for(int i=2;i<=len;i++)
{
while(j&&suffix[j+1]!=query(i-j,i))j=border[j];
if(suffix[j+1]==query(i-j,i))j++;
border[i]=j;
}
}
}A[N];
void Kmp(int x,int y)
{
int j=0;k=1;
int ans=0;
for(int i=1;i<=A[y].len;i++)
{
while(j&&A[x].suffix[j+1]!=A[y].query(i-j,i))j=A[x].border[j];
if(A[x].suffix[j+1]==A[y].query(i-j,i))j++;
if(j==A[x].len)
{
j=A[x].border[j];
ans++;
}
}
printf("%d\n",ans);
}
int T,n,q;
char str[N];
int main()
{
scanf("%d %d %d",&T,&n,&q);
for(int i=1;i<=n;i++)
{
scanf("%s",str+1);
int m=strlen(str+1);
A[i].S.push_back('!');
for(int j=1;j<=m;j++)
A[i].S.push_back(str[j]);
A[i].len=m;
A[i].manacher();
A[i].Kmp();
}
while(q--)
{
int x,y;
scanf("%d %d",&x,&y);
Kmp(x,y);
}
return 0;
}
详细
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
input:
0 2 500000 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
1 1 1 487 1 0 1 487 0 1 0 0 1 1 1 0 487 0 0 1 487 1 1 1 1 487 1 0 0 0 487 487 1 1 487 487 1 0 1 0 1 0 0 487 1 0 1 0 1 1 487 1 1 1 1 1 1 0 1 0 0 0 0 0 0 487 0 1 1 0 1 0 0 1 0 487 487 487 1 1 487 487 1 1 1 1 1 487 0 487 0 0 0 487 0 1 487 487 1 1 1 0 0 1 1 487 1 1 0 1 1 1 1 1 1 487 1 1 0 1 1 0 0 1 0 1 ...
result:
Subtask #2:
score: 0
Time Limit Exceeded
Test #10:
score: 15
Accepted
time: 453ms
memory: 144308kb
input:
0 500000 500000 v s o w f c z u d b z h b e w p n l e i e h g h o q u x n k t z i f e t q b s h o q k n k t d x t u p w l h g j c q n i s o v s u e n c j f u w q g u p v w z w p r d n m v d z n j l o n v y u j x j v a e x r l s x g u a h u c b z k b t g h o g k t l u i c q p v c s s s l i c h t o s ...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 500000 tokens
Test #11:
score: 0
Accepted
time: 375ms
memory: 105320kb
input:
0 250000 500000 di ne pk cw la bt cx hs ku ga rq zq jo zr at ue og sl su ju gy oo om ev df bm jh um vw ts qs we pn pe zc zb nl ld kl pl tk uh cm hn qb xi wb lu kq gf vc eq xe ni se ng kn rt zd bv vb vn ui dz kn do cg nn ct mz op od lu cb ra ib dk lh xh wh ny ws jw lh vk bl ak an rz xv sm zt mp yr an...
output:
1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 500000 tokens
Test #12:
score: 0
Accepted
time: 334ms
memory: 80092kb
input:
0 50000 500000 qkubvtpdzm soafdgztoz dzihbjgzlv qzmgwddcum edjlwzdesz uzdcradqvu keljvoztlv rwibigjyiq txgwbogpxx hpkzemjevp zgygtmqivo vmhpsomqgj icjqyepuzv lgxnfnvmnk wgetijbyql qsglhyjkee enfkhyfory hwzrhlcqfj bhifrgvfly bpuphqsvau yvdgurwpeo vxyypvbpfh ghgrliyqyb vaunorfwvl xzisdbfkbu vpxuecgonr...
output:
0 0 0 1 1 1 0 1 1 0 0 0 0 0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 1 0 0 1 0 0 0 0 1 0 1 1 0 0 0 1 0 0 1 1 1 1 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 ...
result:
ok 500000 tokens
Test #13:
score: 0
Accepted
time: 1005ms
memory: 75360kb
input:
0 5000 500000 wgnhspqfqmsglvytlzswiyhhryunyqtbwgrybapsfazarmqfzeyaqheruzccfiwvosvttasxklvfyiyutasgnqzielbmzfwzneea ksqsaughjpdpmrxyqrnkenvuhhbnxjlgaxoebfgosierjxuhbxxnnupigxqjcmknzuomavqyafbwippqznniqixbbutybznxxlcg jqhxhvoknjktzdegmtdvxapbfobchmgvxavvbksiqekqtjkvvgwkfxsuqueklxlyqlanorcambowdgzvdovf...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 500000 tokens
Test #14:
score: -15
Time Limit Exceeded
input:
0 200 500000 ztvrelbmgkwawltubkecueenrrxoafbslwjaeqvzzppfzxvgycgliaiwhfeyvodpsapqeyjirgclwrdflcqispbtbivlkaiecakocarlmhpdowzwjhxgpjbcccepmpceyyrwwrnmlyyioslgqbppnutbqcxhiyfntvxwslcpqnvmonyevbadqpkhlddixawynfoztkjmfsafyoolgspflnixalfeulgtuymhzpeutrquxqnkhwhezovdksbthwzirpdnhinlvnjijtytwzggcoptflsjhbl...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
Subtask #3:
score: 20
Accepted
Test #32:
score: 20
Accepted
time: 29ms
memory: 83196kb
input:
0 1 1 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
1
result:
ok "1"
Test #33:
score: 0
Accepted
time: 40ms
memory: 78740kb
input:
0 2 1 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
1
result:
ok "1"
Test #34:
score: 0
Accepted
time: 35ms
memory: 81520kb
input:
0 2 1 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
300001
result:
ok "300001"
Test #35:
score: 0
Accepted
time: 24ms
memory: 80000kb
input:
0 2 1 bccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaa...
output:
33334
result:
ok "33334"
Test #36:
score: 0
Accepted
time: 37ms
memory: 81664kb
input:
0 2 1 bccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaabccbaa...
output:
100001
result:
ok "100001"
Test #37:
score: 0
Accepted
time: 30ms
memory: 79808kb
input:
0 2 1 bcdeedcbaabcdeedcbaabcdeedcbaabcdeedcbaabcdeedcbaabcdeedcbaabcdeedcbaabcdeedcbaabcdeedcbaabcdeedcbaabcdeedcbaabcdeedcbaabcdeedcbaabcdeedcbaabcdeedcbaabcdeedcbaabcdeedcbaabcdeedcbaabcdeedcbaabcdeedcbaabcdeedcbaabcdeedcbaabcdeedcbaabcdeedcbaabcdeedcbaabcdeedcbaabcdeedcbaabcdeedcbaabcdeedcbaabcde...
output:
20001
result:
ok "20001"
Test #38:
score: 0
Accepted
time: 30ms
memory: 81616kb
input:
0 100 1 a j w z m h d n f c k z f c m d v o e w t r j j e l q q m y a a q g i e y p k x c q t b c r l n e t x d x w a a p g e v x o r v e n t s t x u y l x bcddcbaabcddcbaabcddcbaabcddcbaabcddcbaabcddcbaabcddcbaabcddcbaabcddcbaabcddcbaabcddcbaabcddcbaabcddcbaabcddcbaabcddcbaabcddcbaabcddcbaabcddcbaa...
output:
74976
result:
ok "74976"
Test #39:
score: 0
Accepted
time: 36ms
memory: 83200kb
input:
0 2 1 epppipfhwh wnybdiecccdcqdrdyrrrzrxizicvvvrvoxpxnpppspbnknmuuupuykckegggqgwctclhhhihvonooxxxrxwujuussswsxltlujjjpjxysyudddydrqeqozzzgznsislcccjcqlilyjgfxccctchvlvqfffhfvcpcyrrrqrstntomxvvvmvgprpawwwpwnjmjyjjjdjpbnbevvvovadmdrzzzpzothtekfffaflnwngkkkxkycncczzzgzsgvgldddjdnqmqyzzzbzwmhmmaaahawrvr...
output:
47042
result:
ok "47042"
Test #40:
score: 0
Accepted
time: 30ms
memory: 83200kb
input:
0 2 1 eoaxlzjsyyyysyyyysysyysyssysyysyssyysyyssysyssyyssysyssyysyyssyyssyysyyssyysssyyssyysyysssyysssysyysysssyyssavvhuqyhpetbpcplkobyavffffnffffnfnffnfnnfnffnfnnffnffnnfnfnnffnnfnfnnffnffnnffnnffnffnnffnnnffnnffnffnnnffnnnfnffnfnnnffnnbbbbsbbbbsbsbbsbssbsbbsbssbbsbbssbsbssbbssbsbssbbsbbssbbssbbsbbs...
output:
4748
result:
ok "4748"
Test #41:
score: 0
Accepted
time: 44ms
memory: 83244kb
input:
0 2 1 llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll...
output:
13476
result:
ok "13476"
Test #42:
score: 0
Accepted
time: 32ms
memory: 83088kb
input:
0 2 1 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz...
output:
47
result:
ok "47"
Test #43:
score: 0
Accepted
time: 32ms
memory: 81580kb
input:
0 2 1 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...
output:
4
result:
ok "4"
Test #44:
score: 0
Accepted
time: 47ms
memory: 82932kb
input:
0 3 1 bbbbabaaabbaaaaabbbbabbabaabbbaaabaababbbabbaababbaaaababbaabbbaabbbababbbbbbababaaababbbbaabaabbaaaabaaabaabaabbbabaabaabbbaaaabaabbabababbaabbaaaaaababbbbabbabbaabaaabaabbbbaababbaabababbaabaaabbaabababbaabaaaababababababbaaaababbbabbababbbabaaaabababbaaabbaaabababbaaaabaaababbbaabaabbababba...
output:
0
result:
ok "0"
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%