提交记录 3954


用户 题目 状态 得分 用时 内存 语言 代码长度
Chuzyh noi18c. 【NOI2018】你的名字 Wrong Answer 8 4 s 762176 KB C++ 2.96 KB
提交时间 评测时间
2018-07-18 20:08:27 2020-07-31 22:08:29
#include<cstdio>
#include<vector>
#include<cstring>
using namespace std;
const int N=1000010;
#define int long long
int n,i,j,tot=1,slink[N*2],trans[N*2][26],endpos[N*2][2],maxlen[N*2],pre[N*2][2];
int top,fir[N*2],ne[N*4],la[N*4],to[N*4],BLOCK,q,l,r;
const int base1=233,base2=97,ha1=1e7+19,ha2=1e7+79;
char s[N],t[N];
int ans;
int HASH[10000100][2];
int newstate(int mx,int* _trans,int _slink)
{
    tot++,maxlen[tot]=mx,slink[tot]=_slink;
    if(_trans)for(int i=0;i<26;i++)trans[tot][i]=_trans[i];
    else for(int i=0;i<26;i++)trans[tot][i]=-1;
    return tot;
}
int addchar(int now,char ch,int which)
{
    int c=ch-'a',v=now;
    int NEW=newstate(maxlen[now]+1,NULL,1);
    while(v!=-1&&trans[v][c]==-1)trans[v][c]=NEW,v=slink[v];
    if(v==-1)
    {
        slink[NEW]=1;
        return NEW;
    }
    int x=trans[v][c];
    if(maxlen[v]+1==maxlen[x])
    {
        slink[NEW]=x;
        return NEW;
    }
    
    int y=newstate(maxlen[v]+1,trans[x],slink[x]);
    slink[x]=slink[NEW]=y;
    
    while(v!=-1&&trans[v][c]==x)
    {
        trans[v][c]=y;
        v=slink[v];
    }
    return NEW;
}
vector<int> hh1,hh2;
void add(int x,int y)
{
    top++,to[top]=y;
    if(fir[x]==0)fir[x]=top;else ne[la[x]]=top;
    la[x]=top;
}
void dfs(int x)
{
    for(int i=fir[x];i;i=ne[i])
    dfs(to[i]),endpos[x][0]+=endpos[to[i]][0],endpos[x][1]+=endpos[to[i]][1];
    endpos[x][0]+=pre[x][0],endpos[x][1]+=pre[x][1];
     
    if(endpos[x][0]==0)ans+=(maxlen[x]-maxlen[slink[x]]);
}
main()
{
	freopen("name.in","r",stdin);
    freopen("name.out","w",stdout);
	scanf("%s",s+1),n=strlen(s+1);BLOCK=1000;
    memset(trans[1],-1,sizeof trans[1]);slink[1]=-1;
    int LA=1;
    for(i=1;i<=n;i++)LA=addchar(LA,s[i],0),pre[LA][0]++;
    scanf("%lld",&q);
    while(q--)
    {
    	scanf("%s",t+1);scanf("%lld%lld",&l,&r);int len=strlen(t+1);ans=0;hh1.clear();hh2.clear();
    	if(len<BLOCK)
//    	if(0)
    	{
    		int now;
    		for(i=1;i<=len;i++)
    		{
    			now=1;int H1=0,H2=0;
    			for(j=i;j<=len;j++)
    			{
    				H1=(H1*base1+t[j])%ha1;
    				H2=(H2*base2+t[j])%ha2;
    				if(now!=-1)now=trans[now][t[j]-'a'];
    				if(now==-1)
					{
						if(!(HASH[H1][0]&&HASH[H2][1]))
						{
							ans++,HASH[H1][0]=HASH[H2][1]=1,hh1.push_back(H1),hh2.push_back(H2);
						}
						
					}
				}
			}
    		printf("%lld\n",ans);
    		for(i=0;i<hh1.size();i++)HASH[hh1[i]][0]=0;
    		for(i=0;i<hh2.size();i++)HASH[hh2[i]][1]=0;
		}else
		{
			int LA=1;
    		for(i=1;i<=len;i++)LA=addchar(LA,t[i],1),pre[LA][1]++;
    		for(i=2;i<=tot;i++)
			add(slink[i],i);

        	dfs(1);
			printf("%lld\n",ans);
			
			
			memset(fir,0,sizeof fir);
			memset(ne,0,sizeof ne);
			memset(to,0,sizeof to);
			memset(la,0,sizeof la);top=0;
			
			memset(trans,0,sizeof trans);
			memset(trans[1],-1,sizeof trans[1]);
			memset(slink,0,sizeof slink);
			memset(endpos,0,sizeof endpos);
			memset(pre,0,sizeof pre);
			tot=1;
			slink[1]=-1;
    		LA=1;
    		for(i=1;i<=n;i++)LA=addchar(LA,s[i],0),pre[LA][0]++;
		}
	}
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1222.314 ms153 MB + 284 KBWrong AnswerScore: 0

Testcase #2223.232 ms153 MB + 580 KBWrong AnswerScore: 0

Testcase #3231.911 ms153 MB + 584 KBWrong AnswerScore: 0

Testcase #44 s579 MB + 944 KBTime Limit ExceededScore: 0

Testcase #54 s579 MB + 944 KBTime Limit ExceededScore: 0

Testcase #6499.061 ms592 MB + 864 KBAcceptedScore: 4

Testcase #7499.676 ms592 MB + 872 KBAcceptedScore: 4

Testcase #81.143 s735 MB + 188 KBWrong AnswerScore: 0

Testcase #91.445 s735 MB + 96 KBWrong AnswerScore: 0

Testcase #102.41 s736 MB + 28 KBWrong AnswerScore: 0

Testcase #112.865 s736 MB + 392 KBWrong AnswerScore: 0

Testcase #123.916 s738 MB + 136 KBWrong AnswerScore: 0

Testcase #134 s737 MB + 764 KBTime Limit ExceededScore: 0

Testcase #144 s740 MB + 464 KBTime Limit ExceededScore: 0

Testcase #154 s739 MB + 148 KBTime Limit ExceededScore: 0

Testcase #164 s744 MB + 268 KBTime Limit ExceededScore: 0

Testcase #174 s740 MB + 572 KBTime Limit ExceededScore: 0

Testcase #184 s740 MB + 824 KBTime Limit ExceededScore: 0

Testcase #194 s741 MB + 1004 KBTime Limit ExceededScore: 0

Testcase #204 s743 MB + 92 KBTime Limit ExceededScore: 0

Testcase #214 s744 MB + 284 KBTime Limit ExceededScore: 0

Testcase #224 s744 MB + 288 KBTime Limit ExceededScore: 0

Testcase #234 s744 MB + 292 KBTime Limit ExceededScore: 0

Testcase #244 s744 MB + 240 KBTime Limit ExceededScore: 0

Testcase #254 s744 MB + 320 KBTime Limit ExceededScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2026-04-17 18:18:57 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠