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. Zabbix使用总结

    1. CentOS 7上启动zabbix-server失败,/var/log/messages中的报错信息如下: Feb :: mysql-server1 systemd: Starting Zabb ...

  2. chrome浏览器插件 Octotree 让你浏览GitHub的时候像IDE 一样提供项目目录

    GitHub 作为代码托管平台,竟然没有提供项目目录,方便用户在线快速浏览项目结构.所以,在线分析项目源码就会变得很繁琐,必须一层一层点击,然后再一次一次地向上返回.要知道,本来 GitHub 网站在 ...

  3. Hadoop框架

    1.Hadoop的整体框架 Hadoop由HDFS.MapReduce.HBase.Hive和ZooKeeper等成员组成,其中最基础最重要元素为底层用于存储集群中所有存储节点文件的文件系统HDFS( ...

  4. Oracle实用地址

    1.详细安装教程 https://jingyan.baidu.com/article/3c48dd34be2a32e10be35881.html

  5. Unity3D — — UGUI之简易背包

    Uinity版本:2017.3 最近在学Siki老师的<黑暗之光RPG>教程,由于教程内用的是NGUI实现,而笔者本人用的是UGUI,所以在这里稍微写一下自己的实现思路(大致上和NGUI一 ...

  6. 管理idea Open Recent

    在微服务开发过程中,随着服务的增加,日常需要在各个服务之间切换,这样idea 的 Open Recent 功能就显得特别有用,但是过多的最近打开记录中包括已经删除的工程或者无用的工程导致影响开发时切换 ...

  7. [paper]MaskFusion: Real-Time Recognition, Tracking and Reconstruction of Multiple Moving Objects

    Before 近期在调研关于RGBD在室内移动机器人下的语义导航的研究.目前帝国理工的Andrew Davison在这边有两个团队在研究,分别是Fusion++ 和 这篇 MaskFusion.这篇是 ...

  8. 用户场景模拟+Spec

    场景模拟: Spec:  浏览包车信息-->登录-->选择包车城市-->选择去/回程-->选择路线-->预定-->选择包车日期-->出发时间和地点--> ...

  9. Photo Cleaner -- proposed by Wei Zhang

    Need想必大家都有用手机或相机记录生活的习惯吧!在旅途中,驴友们见到美丽的风景,往往激动地咔嚓一下拍张照记录下来.完事后发现角度不太好,于是又咔嚓一下……不知不觉中一下照了好多,然而真正需要的只是那 ...

  10. Beta冲刺——day4

    Beta冲刺--day4 作业链接 Beta冲刺随笔集 github地址 团队成员 031602636 许舒玲(队长) 031602237 吴杰婷 031602220 雷博浩 031602134 王龙 ...