QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#22879 | #2135. How Many Strings Are Less | LFCode | WA | 2ms | 20088kb | C++14 | 1.7kb | 2022-03-10 21:27:18 | 2022-04-30 02:00:11 |
Judging History
answer
//什么时候我才能有杜爷一半强啊/kk
//我是傻逼
#include<cstdio>
#include<iostream>
#include<cstring>
#define lg(x) (31-__builtin_clz(x))
using namespace std;
const int N=1000086;
int n,m,q,pc,nt,nans,c[N],prs[N],mark[N],sze[N],depth[N],t[N][26],fa[N][21],f[N][26];
char st[N],str[N];
int read(){
char ch=getchar();int nn=0,ssss=1;
while(ch<'0'||ch>'9'){if(ch=='-')ssss*=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){nn=nn*10+(ch-'0');ch=getchar();}
return nn*ssss;
}
int gc(){char ch=getchar();while(ch<'a'||ch>'z')ch=getchar();return ch-'a';}
bool push(char s[]){
int len=strlen(s+1),np=0;
for(int i=1;i<=len&&i<=m;i++){
int ch=s[i]-'a';
if(!t[np][ch])t[np][ch]=++pc;
np=t[np][ch];c[np]=ch;sze[np]++;
}
mark[np]++;return true;
}
bool dp(int np,int lst,int dep,int ps){
prs[np]=ps;fa[np][0]=lst;depth[np]=dep;
for(int i=1;(1<<i)<dep;i++)fa[np][i]=fa[fa[np][i-1]][i-1];
ps+=mark[np];
for(int i=0;i<26;i++){
if(!t[np][i]){f[np][i]=np;continue;}
dp(t[np][i],np,dep+1,ps);
f[np][i]=f[t[np][i]][i];
ps+=sze[t[np][i]];
}
return true;
}
int gf(int np,int dep){
if(depth[np]<dep)return -1;
for(int i=lg(depth[np]);i+1;i--)
if(depth[np]-(1<<i)>=dep)
np=fa[np][i];
return np;
}
int main(){
n=read();q=read();cin>>(st+1);m=strlen(st+1);
for(int i=1;i<=m;i++){
int ch=st[i]-'a';
if(!t[nt][ch])t[nt][ch]=++pc;
nt=t[nt][ch];
}
for(int i=1;i<=n;i++){cin>>(str+1);push(str);}
dp(0,0,0,0);printf("%d\n",nans=prs[nt]);
for(int i=1;i<=q;i++){
int p=read();int x=gc();int nf=gf(nt,p-1);
if(nf!=-1){
nt=f[nf][x];nans=prs[nt];
if(depth[nt]<m){
for(int j=0;j<x;j++)if(t[nt][j])nans+=sze[j];
nans+=mark[nt];
}
}
printf("%d\n",nans);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 20044kb
input:
4 3 anatoly boris anatooo anbbbbu anba 5 o 3 b 7 x
output:
0 0 2 3
result:
ok 4 number(s): "0 0 2 3"
Test #2:
score: 0
Accepted
time: 2ms
memory: 20052kb
input:
5 5 abcde buz ababa build a aba 1 b 3 z 2 u 4 z 1 a
output:
3 3 3 4 4 1
result:
ok 6 numbers
Test #3:
score: -100
Wrong Answer
time: 2ms
memory: 20088kb
input:
1 1 abababababababababababab ababababababababababababab 23 b
output:
0 0
result:
wrong answer 2nd numbers differ - expected: '1', found: '0'