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. IOS免越狱虚拟定位修改工具共享 Jocation

    Jocation IOS虚拟定位修改器 具体使用方法可以按照 location cleaned软件相同的操作. 主要是因为本人有一部 IphoneX 和Iphone Xs Max 网上的locatio ...

  2. allegro 封装 (引脚编号修改)

    1. 打开dra文件在find里面 off all  然后只点击text 2.点击需要更改的焊盘 3.菜单栏edit - text 4.弹出窗口修改即可

  3. 做游戏的小伙伴们注意了,DDoS还可以这样破!

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由腾讯游戏云发表于云+社区专栏 作者:腾讯DDoS安全专家.腾讯云游戏安全专家haroldchen 摘要:在游戏出海的过程中,DDoS攻 ...

  4. CentOS-7.x Yum Repo Mirror

    一. 环境 1.1 主机信息 主机 OS Storage 备注 100.64.140.101 centos 7.6 /dev/sdb > 100GB 1.selinux disable; 2.放 ...

  5. LAXCUS大数据操作系统节点挂掉后的处理

    昨天回公司加班跑一个LAXCUS大数据应用,JVM直接挂了,没有留下任何异常信息,查看代码,也没有内存泄漏的问题.百思不得姐,只好去求教LAXCUS大数据操作系统的技术客服,客服查看了故障节点配置.日 ...

  6. 关于T/G/M/K

    //扫盲贴 K, G, T,都是表数量,只是个数字,在不同的场合下表示的不同.在计算机行业中,这几个量可用来表示数据传输速度和容量,下面分别讨论,希望不了解的朋友不要被某知道上的误解了.如果有什么错误 ...

  7. LeetCode 70. Climbing Stairs爬楼梯 (C++)

    题目: You are climbing a stair case. It takes n steps to reach to the top. Each time you can either cl ...

  8. Notes of Daily Scrum Meeting(12.19)

    今天工作进展的速度别昨天稍有提高,希望大家再接再厉!加油! 团队任务总结如下: 团队成员 今日团队工作 陈少杰 重新尝试使用get等方法进行网络连接的调试 王迪 调试搜索功能中测出的问题 金鑫 测试已 ...

  9. 【iMooc】全面解析java注解

    在慕课上学习了一个关于java注解的课程,下面是笔记以及一些源码. Annotation——注解 1.JDK中的注解 JDK中包括下面三种注解: @Override:标记注解(marker annot ...

  10. npm 报错unable to verify the first certificate

    npm总是报错:unable to verify the first certificate 原创 2017年09月30日 11:06:10 https://blog.csdn.net/nicexib ...