一直WA……找了半天错的发现居然是解密那里的mask其实是不能动的……传进去的会变,但是真实的那个不会变……

然后就是后缀自动机,用LCT维护parent树了……注意不能makeroot,因为自动机的根是不会变的(同理也不能翻转区间),其实就是低配LCT(?)

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=3000005;
int q,n,m,fa[N],ch[N][27],dis[N],la,cur=1,con=1,ma,st[N],top;
char o[10],s[N];
struct qwe
{
int c[2],f,s,lz;
}t[N<<1];
bool srt(int x)
{
return t[t[x].f].c[0]!=x&&t[t[x].f].c[1]!=x;
}
void ud(int x,int y)
{
if(x)
t[x].s+=y,t[x].lz+=y;
}
void pd(int x)
{
if(t[x].lz)
{
ud(t[x].c[0],t[x].lz);
ud(t[x].c[1],t[x].lz);
t[x].lz=0;
}
}
void zhuan(int x)
{
int y=t[x].f,z=t[y].f,l=(t[y].c[0]!=x),r=l^1;
if(!srt(y))
t[z].c[t[z].c[0]!=y]=x;
t[x].f=z;
t[t[x].c[r]].f=y,t[y].c[l]=t[x].c[r];
t[x].c[r]=y,t[y].f=x;
}
void splay(int x)
{
top=0;
st[++top]=x;
for(int i=x;!srt(i);i=t[i].f)
st[++top]=t[i].f;
for(int i=top;i>=1;i--)
pd(st[i]);
while(!srt(x))
{
int y=t[x].f,z=t[y].f;
if(!srt(y))
((t[y].c[0]==x)^(t[z].c[0]==y))?zhuan(x):zhuan(y);
zhuan(x);
}
}
void acc(int x)
{
for(int i=0;x;i=x,x=t[x].f)
{
splay(x);
t[x].c[1]=i;
}
}
void lk(int x,int y)
{
t[x].f=y;
acc(y);
splay(y);
ud(y,t[x].s);
}
void ct(int x)
{
acc(x);
splay(x);
ud(t[x].c[0],-t[x].s);
t[t[x].c[0]].f=0,t[x].c[0]=0;
}
void ins(int c)
{
la=cur,dis[cur=++con]=dis[la]+1,t[cur].s=1;
int p=la;
for(;p&&!ch[p][c];p=fa[p])
ch[p][c]=cur;
if(!p)
fa[cur]=1,lk(cur,1);
else
{
int q=ch[p][c];
if(dis[q]==dis[p]+1)
fa[cur]=q,lk(cur,q);
else
{
int nq=++con;
dis[nq]=dis[p]+1;
memcpy(ch[nq],ch[q],sizeof(ch[q]));
fa[nq]=fa[q];
lk(nq,fa[q]);
fa[q]=fa[cur]=nq;
ct(q),lk(q,nq),lk(cur,nq);
for(;ch[p][c]==q;p=fa[p])
ch[p][c]=nq;
}
}
}
int ques(int len)
{
int nw=1;
for(int i=0;i<len;i++)
if(!(nw=ch[nw][s[i]-'A']))
return 0;
splay(nw);
return t[nw].s;
}
int main()
{
scanf("%d%s",&q,s+1);
n=strlen(s+1);
for(int i=1;i<=n;i++)
ins(s[i]-'A');
while(q--)
{
scanf("%s%s",o+1,s);
m=strlen(s);
for(int i=0,re=ma;i<m;i++)
{
re=(re*131+i)%m;
swap(s[i],s[re]);
}
if(o[1]=='Q')
{
int ans=ques(m);
printf("%d\n",ans);
ma^=ans;
}
else
{
for(int i=0;i<m;i++)
ins(s[i]-'A');
}
}
return 0;
}

bzoj 2555: SubString【后缀自动机+LCT】的更多相关文章

  1. bzoj 2555 SubString —— 后缀自动机+LCT

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2555 建立后缀自动机,就可以直接加入新串了: 出现次数就是 Right 集合的大小,需要查询 ...

  2. bzoj 2555: SubString 后缀自动机+LCT

    2555: SubString Time Limit: 30 Sec  Memory Limit: 512 MBSubmit: 688  Solved: 235[Submit][Status][Dis ...

  3. bzoj 2555 SubString——后缀自动机+LCT

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2555 要维护 right 集合的大小.因为 fa 会变,且 fa 构成一棵树,所以考虑用 L ...

  4. BZOJ 2555: SubString 后缀自动机_LCT

    很水的一道题,就是有些细节没注意到. 比如说将调试信息误以为是最终结果而多调了20分钟QAQ ..... 我们注意到,每新加一个节点,改变的是该节点沿着 Parent 走一直走到根节点. 对应的,在 ...

  5. bzoj 2555 SubString(SAM+LCT)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2555 [题意] 给定一个字符串,可以随时插入字符串,提供查询s在其中作为连续子串的出现 ...

  6. 【BZOJ2555】SubString 后缀自动机+LCT

    [BZOJ2555]SubString Description 懒得写背景了,给你一个字符串init,要求你支持两个操作         (1):在当前字符串的后面插入一个字符串         (2 ...

  7. bzoj 5408: string 后缀自动机 + LCT

    联赛前练练码力. code: #include <vector> #include <cstdio> #include <cstring> #include < ...

  8. ●BZOJ 2555 SubString

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=2555题解: 后缀自动机+LCT 不难发现,对于输入的询问串,在自动机里trans后的到的状态 ...

  9. 字符串(LCT,后缀自动机):BZOJ 2555 SubString

    2555: SubString Time Limit: 30 Sec  Memory Limit: 512 MBSubmit: 1620  Solved: 471 Description 懒得写背景了 ...

随机推荐

  1. iOS_40_核心动画

    核心动画之CATransition转场动画 终于效果图: 核心动画之CAKeyFrameAnimation,图标抖动效果 终于效果图: 核心动画之CAAnimationGroup(动画组) 终于效果图 ...

  2. 几个简单的程序看PHP的垃圾回收机制

    每一种计算机语言都有自己的自动垃圾回收机制,让程序员不必过分关心程序内存分配,php也不例外,但是在面向对象编程(OOP)编程中,有些对象需要显式的销毁,防止程序执行内存溢出. 一.PHP 垃圾回收机 ...

  3. Qt、C++ 简易计算器

    Qt.C++实现简易计算器: 以下内容是我实现这个简易计算器整个过程,其中包括我对如何实现这个功能的思考.中途遇到的问题.走过的弯路 整个实现从易到难,计算器功能从简单到复杂,最开始设计的整个实现步骤 ...

  4. label 对齐

    <label for="username">用户名</label> <input type="text" id="use ...

  5. mvn -v 报错解决办法

    由于近期公司需求,我找到了个maven教程:http://wentao365.iteye.com/blog/903396 安装maven其实很简单,就是在Apache官网下载需要的maven包,然后配 ...

  6. 【读后感】Netty 系列之 Netty 高性能之道 - 相比 Mina 怎样 ?

    [读后感]Netty 系列之 Netty 高性能之道 - 相比 Mina 怎样 ? 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商 ...

  7. HDU 6073 Matching In Multiplication dfs遍历环 + 拓扑

    Matching In Multiplication Problem DescriptionIn the mathematical discipline of graph theory, a bipa ...

  8. bzoj3136: [Baltic2013]brunhilda

    这个题为什么会放在数据结构啊 首先因为有决策包容性,对于一个n每次必然选择一个n%p最大的p,令n减n%p 设fi表示i变成0的步数的话,同样我们可以知道f是有单调性的 假如fd能转移到fk,首先d一 ...

  9. ajax验证用户名 当用户名框的数据改变时 执行ajax方法

    ajax验证用户名 当用户名框的数据改变时 执行ajax方法 <html xmlns="http://www.w3.org/1999/xhtml" ><head ...

  10. Python(1)(安装与基本使用)

    1.Python的下载和安装我就不废话了,百度上都有. 我安装的是Python 3.4.3 64bit 安装完之后,打开Cmd,输入Python 显示以上相同,按照百度的意思就是安装成功. 2.配置环 ...