算是学会sam了吧……

原题:

懒得写背景了,给你一个字符串init,要求你支持两个操作
    
    (1):在当前字符串的后面插入一个字符串
    
    (2):询问字符串s在当前字符串中出现了几次?(作为连续子串)
    
    你必须在线支持这些操作。
   字符串最终长度 <= 600000,询问次数<= 10000,询问总长度<= 3000000

因为sam添点本来就是动态的所以动态往后连接串就不用管了

问题是维护right集的大小,如果新添了一个点np那么从np一直到sam的根right集的大小都会+1对吧

暴力修改即可?以前是可以的,现在新添一组数据卡掉了……

那咋办,动态树上进行路径修改,lct口贝

值得注意的是修改的路径是当前点到原树根的,lct上修改的时候需要把原树根钦定为lct的根然后再access再splay再修改

注意询问串可能比插入串和起始串长,如果共用一个字符数组的话要开成3e6……

注意题中给出的强制在线函数中mask是个局部变量……也就是说转码的时候mask不会变,询问的时候才会变……

代码:

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int qwq=;
int m; char s[],t[]; int n;
int nxt[][],fth[],mx[],sz[],lst=,npt=;
int c[][],fa[],v[],dt[],rvs[];
int stck[],tp=;
inline bool isrt(int x){ return (c[fa[x]][]!=x)&(c[fa[x]][]!=x);}
inline void pshd(int x){
v[c[x][]]+=dt[x],dt[c[x][]]+=dt[x];
v[c[x][]]+=dt[x],dt[c[x][]]+=dt[x];
dt[x]=;
if(!rvs[x]) return ;
rvs[c[x][]]^=,rvs[c[x][]]^=,rvs[x]=;
swap(c[x][],c[x][]);
}
inline void rtt(int x){
int y=fa[x],z=fa[fa[x]],l,r;
r=(c[y][]==x); l=r^;
if(!isrt(y)) c[z][c[z][]==y]=x;
fa[x]=z,fa[y]=x,fa[c[x][r]]=y;
c[y][l]=c[x][r],c[x][r]=y;
}
inline void sply(int x){
stck[tp=]=x;
for(int i=x;!isrt(i);i=fa[i]) stck[++tp]=fa[i];
while(tp) pshd(stck[tp--]);
while(!isrt(x)){
if(!isrt(fa[x])) rtt((c[fa[x]][]==x)^(c[fa[fa[x]]][]==fa[x])?x:fa[x]);
rtt(x);
}
}
inline void accs(int x){ for(int i=;x;sply(x),c[x][]=i,x=fa[i=x]);}
inline void qdrt(int x){ accs(x),sply(x),rvs[x]^=;}
inline void lk(int x,int y){ qdrt(x),fa[x]=y,sply(x);}
inline void ct(int x,int y){ qdrt(x),accs(y),sply(y),fa[x]=c[y][]=;}
inline void bf(int x,int y){ qdrt(),accs(x),sply(x),v[x]+=y,dt[x]+=y;}
inline int sch(int x){ sply(x); return v[x];}
void rds(){
scanf("%s",s); n=strlen(s); int tmp=qwq;
for(int i=;i<n;++i){
tmp=(tmp*+i)%n;
swap(s[i],s[tmp]);
}
}
/*void ist(int x){
int p=lst,np=lst=++npt;
mx[np]=mx[p]+1; sz[np]=0;
while((!nxt[p][x])&((!p)^1)) nxt[p][x]=np,p=fth[p];
if(!p) fth[np]=1;
else{
int q=nxt[p][x];
if(mx[q]==mx[p]+1) fth[np]=q;
else{
int nq=++npt; mx[nq]=mx[p]+1; sz[nq]=sz[q];
memcpy(nxt[nq],nxt[q],sizeof(nxt[q]));
fth[nq]=fth[q],fth[q]=fth[np]=nq;
while(nxt[p][x]==q) nxt[p][x]=nq,p=fth[p];
}
}
while(np) ++sz[np],np=fth[np];
}*/
void ist(int x){
int p=lst,np=lst=++npt;
mx[np]=mx[p]+; v[np]=;
while((!nxt[p][x])&((!p)^)) nxt[p][x]=np,p=fth[p];
if(!p) fth[np]=,lk(np,);
else{
int q=nxt[p][x];
if(mx[q]==mx[p]+) fth[np]=q,lk(np,q);
else{
int nq=++npt; mx[nq]=mx[p]+; v[nq]=sch(q);
memcpy(nxt[nq],nxt[q],sizeof(nxt[q]));
ct(q,fth[q]),lk(nq,fth[q]),lk(q,nq),lk(np,nq);
fth[nq]=fth[q],fth[q]=fth[np]=nq;
while(nxt[p][x]==q) nxt[p][x]=nq,p=fth[p];
}
}
bf(np,);
//cout<<sch(5)<<" "<<fth[3]<<endl;
}
int qr(){
int tmp=;
for(int i=;i<n;++i) tmp=nxt[tmp][s[i]-'A'];
return tmp?sch(tmp):;
}
int main(){freopen("ddd.in","r",stdin);
cin>>m; scanf("%s",s); n=strlen(s);
for(int i=;i<n;++i) ist(s[i]-'A');
while(m--){
scanf("%s",t); rds();
if(t[]=='A') for(int i=;i<n;++i) ist(s[i]-'A');
else{ int tmp=qr(); qwq^=tmp; printf("%d\n",tmp);}
}
return ;
}

【BZOJ2555】SubString的更多相关文章

  1. 【BZOJ2555】SubString(后缀自动机,Link-Cut Tree)

    [BZOJ2555]SubString(后缀自动机,Link-Cut Tree) 题面 BZOJ 题解 这题看起来不难 每次要求的就是\(right/endpos\)集合的大小 所以搞一个\(LCT\ ...

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

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

  3. 【BZOJ-2555】SubString 后缀自动机 + LinkCutTree

    2555: SubString Time Limit: 30 Sec  Memory Limit: 512 MBSubmit: 1936  Solved: 551[Submit][Status][Di ...

  4. 【bzoj2555】 SubString

    http://www.lydsy.com/JudgeOnline/problem.php?id=2555 (题目链接) 题意 给出一个初始串,维护两个操作.在原串后面加入一个字符串:询问某个字符串在原 ...

  5. 【BZOJ2555】SubString(后缀自动机,LCT)

    题意:给你一个字符串init,要求你支持两个操作 (1):在当前字符串的后面插入一个字符串 (2):询问字符串s在当前字符串中出现了几次?(作为连续子串) 你必须在线支持这些操作. 长度 <= ...

  6. 【leetcode】Substring with Concatenation of All Words

    Substring with Concatenation of All Words You are given a string, S, and a list of words, L, that ar ...

  7. 【leetcode】Substring with Concatenation of All Words (hard) ★

    You are given a string, S, and a list of words, L, that are all of the same length. Find all startin ...

  8. 【LeetCode】哈希表 hash_table(共88题)

    [1]Two Sum (2018年11月9日,k-sum专题,算法群衍生题) 给了一个数组 nums, 和一个 target 数字,要求返回一个下标的 pair, 使得这两个元素相加等于 target ...

  9. 【LeetCode】字符串 string(共112题)

    [3]Longest Substring Without Repeating Characters (2019年1月22日,复习) [5]Longest Palindromic Substring ( ...

随机推荐

  1. Lintcode482-Binary Tree Level Sum-Easy

    482. Binary Tree Level Sum Given a binary tree and an integer which is the depth of the target level ...

  2. 全局解释器锁GIL & 线程锁

    1.GIL锁(Global Interpreter Lock) Python代码的执行由Python虚拟机(也叫解释器主循环)来控制.Python在设计之初就考虑到要在主循环中,同时只有一个线程在执行 ...

  3. struts2注释返回json数据

  4. Redis出现的问题

    1):Could not connect to Redis at 127.0.0.1:6379: Connection refused 分析: 1-1:虚拟机中的 6379 端口可能没有开启 查看虚拟 ...

  5. doctrine/annotation 的简单使用

    <?php // 错误处理机制 register_shutdown_function('myShutDown'); set_error_handler('myError'); set_excep ...

  6. Oracle单机Rman笔记[0]---环境准备

    A. 安装操作系统rhel6.6,关闭防火墙,修改网卡配置IP(略)PS:1.默认分区选项(第二项,默认为LVM),然后进行调整2.安装类型选择“桌面”3.安装后 分配IP.调整防火墙.测试SSH B ...

  7. python安装requests

    下面是requests的安装步骤: 1.如果系统已经装了Python,把D:\python3.6.5\Scripts添加到系统的环境变量PATH后面 2.cmd下cd到这个目录下D:\Python3. ...

  8. 各大型网站架构分析收集-原网址http://blog.csdn.net/lovingprince/article/details/3379710

    1. PlentyOfFish 网站架构学习http://www.dbanotes.net/arch/plentyoffish_arch.html 采取 Windows 技术路线的 Web 2.0 站 ...

  9. UVa 10340 - All in All 水题 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  10. 从本地新建项目到提交到github

    1.我是在windows下操作的,所以需要下载个msysgit,这个是git的windows版本. 2.在项目(假设项目为store)根目录下,鼠标右键,点击git bash here 3.将项目从本 ...