bzoj 2555: SubString【后缀自动机+LCT】
一直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】的更多相关文章
- bzoj 2555 SubString —— 后缀自动机+LCT
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2555 建立后缀自动机,就可以直接加入新串了: 出现次数就是 Right 集合的大小,需要查询 ...
- bzoj 2555: SubString 后缀自动机+LCT
2555: SubString Time Limit: 30 Sec Memory Limit: 512 MBSubmit: 688 Solved: 235[Submit][Status][Dis ...
- bzoj 2555 SubString——后缀自动机+LCT
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2555 要维护 right 集合的大小.因为 fa 会变,且 fa 构成一棵树,所以考虑用 L ...
- BZOJ 2555: SubString 后缀自动机_LCT
很水的一道题,就是有些细节没注意到. 比如说将调试信息误以为是最终结果而多调了20分钟QAQ ..... 我们注意到,每新加一个节点,改变的是该节点沿着 Parent 走一直走到根节点. 对应的,在 ...
- bzoj 2555 SubString(SAM+LCT)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2555 [题意] 给定一个字符串,可以随时插入字符串,提供查询s在其中作为连续子串的出现 ...
- 【BZOJ2555】SubString 后缀自动机+LCT
[BZOJ2555]SubString Description 懒得写背景了,给你一个字符串init,要求你支持两个操作 (1):在当前字符串的后面插入一个字符串 (2 ...
- bzoj 5408: string 后缀自动机 + LCT
联赛前练练码力. code: #include <vector> #include <cstdio> #include <cstring> #include < ...
- ●BZOJ 2555 SubString
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=2555题解: 后缀自动机+LCT 不难发现,对于输入的询问串,在自动机里trans后的到的状态 ...
- 字符串(LCT,后缀自动机):BZOJ 2555 SubString
2555: SubString Time Limit: 30 Sec Memory Limit: 512 MBSubmit: 1620 Solved: 471 Description 懒得写背景了 ...
随机推荐
- eclipse 配置执行hadoop 2.7 程序样例參考步骤
前提:你搭建好了hadoop 2.x的linux环境,并可以成功执行.还有就是window可以訪问到集群.over 1. hfds-site.xml 添加属性:关闭集群的权限校验.windows的用户 ...
- CellularAutomation(细胞自己主动机)
CellularAutomation(细胞自己主动机) 细胞自己主动机(英语:Cellular automaton).又称格状自己主动机.元胞自己主动机,是一种离散模型,在可算性理论.数学及理论生物学 ...
- APACHE局域网配置域名访问
/** * * @email 514320008@qq.com * @author jshaibozhong * */ 1,打开APACHE的目录 \Apache2\conf\extra\httpd ...
- Unicode解码转换为中文
Unicode转中文2:Regex.Unescape(string str);str格式:"\uxxxx" ,举例:"\u300d"
- android经常使用正则工具类
此类提供日常开发中经常使用的正则验证函数.比方:邮箱.手机号.电话号码.身份证号码.日期.数字.小数.URL.IP地址等.使用Pattern对象的matches方法进行整个字符匹配,调用该方法相当于: ...
- (转) Universal-Image-Loader使用大全(史上最屌)
转载自http://blog.csdn.net/zenjj11/article/details/38728481 项目介绍: Android上最让人头疼的莫过于从网络获取图片.显示.回收,不论什么一个 ...
- mt7620 wifi driver
<*> Ralink RT2860 802.11n AP support [*] LED Support [*] WSC (WiFi Simple Config) [*] WSC 2.0( ...
- java 的File文件
文件是计算中一种主要的数据存储形式. 首先介绍一下,绝对路径和相对路径.绝对路径是书写完整路径,相对路径是值书写文件的部分路径. d:\java\hello.java 就是据对路径.包括完整的路径d ...
- monitor and move the log content to our big data system
Apache Flume HDFS Sink Tutorial | HowToProgram https://howtoprogram.xyz/2016/08/01/apache-flume-hdfs ...
- Handler有何作用?怎样使用?
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u012974916/article/details/24580405 一 Handler作用和概念 ...