http://www.lydsy.com/JudgeOnline/problem.php?id=2555

后缀自动机,用LCT维护parent树

一个串的出现次数 = parent 树 上 其所在状态 的 子树 叶节点 | Right | 之和

若在parent中np的子节点中加一个节点p,设p的 | Right | = sum,那么 根节点到np 的整条链上的所有状态的 | Right | 都要 + sum

若更换掉q原来的父节点, 设q的 | Right | = sum,那么 根节点到q 的整条链上的所有状态的 | Right | 都要 -  sum

注意  decodeWithMask mask的修改 不影响全局的mask,全局的mask 只 会受 last_ans的影响

三个 无脑shabi错误的血泪史:

#include<cstdio>
#include<cstring>
#include<iostream> using namespace std; #define N 600002 char s[]; int tot=,fa[N<<],len[N<<],ch[N<<][];
int p,q,np,nq,last=; int mask;
string chars; int sum[N<<],tag[N<<];
int Sfa[N<<],Sch[N<<][]; int st[N<<],top; void decodeWithMask(int mask)
{
scanf("%s",s);
chars=s;
int n=chars.length();
for (int j=;j<n;j++)
{
mask=(mask*+j)%n;
char t=chars[j];
chars[j]=chars[mask];
chars[mask]=t;
}
} bool isroot(int x)
{
return Sch[Sfa[x]][]!=x && Sch[Sfa[x]][]!=x;
} bool getson(int x)
{
return Sch[Sfa[x]][]==x;
} void tagging(int x,int y)
{
sum[x]+=y; tag[x]+=y;
} void down(int x)
{
if(!tag[x]) return;
if(Sch[x][]) tagging(Sch[x][],tag[x]);
if(Sch[x][]) tagging(Sch[x][],tag[x]);
tag[x]=;
} void rotate(int x)
{
int y=Sfa[x],z=Sfa[y]; int k=getson(x);
if(!isroot(y)) Sch[z][Sch[z][]==y]=x;
Sch[y][k]=Sch[x][k^]; Sch[x][k^]=y;
Sfa[x]=z; Sfa[y]=x; Sfa[Sch[y][k]]=y;
} void splay(int x)
{
st[top=]=x;
for(int i=x;!isroot(i);i=Sfa[i]) st[++top]=Sfa[i];
for(int i=top;i;--i) down(st[i]);
int y;
while(!isroot(x))
{
y=Sfa[x];
if(!isroot(y)) rotate(getson(y)==getson(x) ? y : x);
rotate(x);
}
} void access(int x)
{
int t=;
while(x)
{
splay(x);
Sch[x][]=t;
t=x; x=Sfa[x];
}
} void link(int x,int f)
{
Sfa[x]=f;
access(f);
splay(f);
tagging(f,sum[x]);
} void cut(int x)
{
access(x);
splay(x);
tagging(Sch[x][],-sum[x]);
Sfa[Sch[x][]]=;
Sch[x][]=;
} void extend(int c)
{
len[np=++tot]=len[last]+;
sum[np]++;
for(p=last;p && !ch[p][c]; p=fa[p]) ch[p][c]=np;
if(!p) fa[np]=,link(np,);
else
{
q=ch[p][c];
if(len[q]==len[p]+) fa[np]=q,link(np,q);
else
{
len[nq=++tot]=len[p]+;
memcpy(ch[nq],ch[q],sizeof(ch[nq]));
fa[nq]=fa[q]; link(nq,fa[q]);
fa[q]=fa[np]=nq;
cut(q); link(q,nq); link(np,nq);
for(;ch[p][c]==q;p=fa[p]) ch[p][c]=nq;
}
}
last=np;
} void build()
{
scanf("%s",s+);
int n=strlen(s+);
for(int i=;i<=n;++i) extend(s[i]-'A');
} void add()
{
decodeWithMask(mask);
int n=chars.length();
for(int i=;i<n;++i) extend(chars[i]-'A');
} int query()
{
decodeWithMask(mask);
int n=chars.length();
int now=;
for(int i=;i<n;++i)
if(!(now=ch[now][chars[i]-'A'])) return ;
splay(now);
return sum[now];
} int main()
{
int T,ans;
scanf("%d",&T);
build();
while(T--)
{
scanf("%s",s);
if(s[]=='A') add();
else
{
ans=query();
printf("%d\n",ans);
mask^=ans;
}
}
}

bzoj千题计划285:bzoj2555: SubString的更多相关文章

  1. bzoj千题计划300:bzoj4823: [Cqoi2017]老C的方块

    http://www.lydsy.com/JudgeOnline/problem.php?id=4823 讨厌的形状就是四联通图 且左右各连一个方块 那么破坏所有满足条件的四联通就好了 按上图方式染色 ...

  2. bzoj千题计划196:bzoj4826: [Hnoi2017]影魔

    http://www.lydsy.com/JudgeOnline/problem.php?id=4826 吐槽一下bzoj这道题的排版是真丑... 我还是粘洛谷的题面吧... 提供p1的攻击力:i,j ...

  3. bzoj千题计划280:bzoj4592: [Shoi2015]脑洞治疗仪

    http://www.lydsy.com/JudgeOnline/problem.php?id=4592 注意操作1 先挖再补,就是补的范围可以包含挖的范围 SHOI2015 的题 略水啊(逃) #i ...

  4. bzoj千题计划177:bzoj1858: [Scoi2010]序列操作

    http://www.lydsy.com/JudgeOnline/problem.php?id=1858 2018 自己写的第1题,一遍过 ^_^ 元旦快乐 #include<cstdio> ...

  5. bzoj千题计划317:bzoj4650: [Noi2016]优秀的拆分(后缀数组+差分)

    https://www.lydsy.com/JudgeOnline/problem.php?id=4650 如果能够预处理出 suf[i] 以i结尾的形式为AA的子串个数 pre[i] 以i开头的形式 ...

  6. bzoj千题计划304:bzoj3676: [Apio2014]回文串(回文自动机)

    https://www.lydsy.com/JudgeOnline/problem.php?id=3676 回文自动机模板题 4年前的APIO如今竟沦为模板,,,╮(╯▽╰)╭,唉 #include& ...

  7. bzoj千题计划292:bzoj2244: [SDOI2011]拦截导弹

    http://www.lydsy.com/JudgeOnline/problem.php?id=2244 每枚导弹成功拦截的概率 = 包含它的最长上升子序列个数/最长上升子序列总个数 pre_len ...

  8. bzoj千题计划278:bzoj4590: [Shoi2015]自动刷题机

    http://www.lydsy.com/JudgeOnline/problem.php?id=4590 二分 这么道水题 没long long WA了两发,没判-1WA了一发,二分写错WA了一发 最 ...

  9. bzoj千题计划250:bzoj3670: [Noi2014]动物园

    http://www.lydsy.com/JudgeOnline/problem.php?id=3670 法一:KMP+st表 抽离nxt数组,构成一棵树 若nxt[i]=j,则i作为j的子节点 那么 ...

随机推荐

  1. Python3.7 + jupyter安装(CentOS6.5)

    Python3.7 + jupyter安装(CentOS6.5) 方法一(anaconda): anaconda是一个开源的Python发行版本 包含conda,python等大量的科学包以及依赖 优 ...

  2. 机器学习之线性回归使用Python和tensorflow实现

    导入依赖包 import tensorflow as tf import numpy as np import matplotlib.pylab as plt from pylab import mp ...

  3. shell 的 export命令

    export 功能说明:设置或显示环境变量.语 法:export [-fnp][变量名称]=[变量设置值]补充说明:在shell中执行程序时,shell会提供一组环境变量.export可新增,修改或删 ...

  4. python发送邮件脚本ssl 465端口

    #coding:utf8 from smtplib import SMTP_SSL from email.header import Header from email.mime.text impor ...

  5. 20135220谈愈敏Blog5_系统调用(下)

    系统调用(下) 谈愈敏 原创作品转载请注明出处 <Linux内核分析>MOOC课程 http://mooc.study.163.com/course/USTC-1000029000 给Me ...

  6. 用C语言编程自动生成四则运算

    #include<stdio.h>#include<stdlib.h>#include <time.h>#define N 30main(){ int a,b,k, ...

  7. 我们的团队-IT梦想队

    IT梦想队 队长:李遇塘 队员:王长.周兴荣.朱岭杰.马婧婧 团队宣言:  一匹狼战斗力低,但一群狼的我们无所畏惧!李遇塘http://www.cnblogs.com/Liyutang/ 王 长htt ...

  8. SQL Server 删除重复数据只保留一条

    DELETE FROM Bus_TerminalMessage_Keywords WHERE Content IN (select Content from Bus_TerminalMessage_K ...

  9. 初学Hadoop之单机模式环境搭建

    本文仅作为学习笔记,供大家初学Hadoop时学习参考.初学Hadoop,欢迎有经验的朋友进行指导与交流! 1.安装CentOS7 准备 CentOS系统镜像CentOS-7.0-1406-x86_64 ...

  10. ElasticSearch 2 (22) - 语言处理系列之标记规范化

    ElasticSearch 2 (22) - 语言处理系列之标记规范化 摘要 将文本拆解成标记只是工作的一半.为了使这些标记更容易被搜索到,它们需要经过一个规范化的处理过程,以移除相同单词间不重要的差 ...