https://www.lydsy.com/JudgeOnline/problem.php?id=2555

(1):在当前字符串的后面插入一个字符串
(2):询问字符串s在当前字符串中出现了几次?(作为连续子串)
你必须在线支持这些操作。

参考:https://www.cnblogs.com/zcysky/p/6851553.html

动态加字符串很容易想到后缀自动机。

如果暴力更新size(或者叫right?)以前是能过的,现在过不了。

但其实parent树本身就是树,用lct维护一下就可做了。

(树根和朝向一定所以不用rev当然用了也没人拦你。)

(很gg,更新lct需要打标记pushdown而不是upt,cut的节点也不要搞错了。)

#include<cstdio>
#include<iostream>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cctype>
using namespace std;
typedef long long ll;
const int N=;
struct tree{
int a[],fa,l;
}ti[N];
char s[],ch[];
int last,cnt;
int a[N],w[N],size[N],tag[N];
int n,m,r,fa[N],tr[N][],q[N];
inline void add(int x,int y){if(x)tag[x]+=y,size[x]+=y;}
inline bool get(int x){
return tr[fa[x]][]==x;
}
inline bool isroot(int x){
if(!fa[x])return ;
return tr[fa[x]][]!=x&&tr[fa[x]][]!=x;
}
inline void push(int x){
if(!tag[x])return;
add(tr[x][],tag[x]);
add(tr[x][],tag[x]);
tag[x]=;
}
inline void rotate(int x){
int y=fa[x],z=fa[y],which=get(x);
if(z&&!isroot(y))tr[z][tr[z][]==y]=x;
tr[y][which]=tr[x][which^];fa[tr[y][which]]=y;
fa[y]=x;tr[x][which^]=y;fa[x]=z;
}
inline void splay(int x){
q[r=]=x;
for(int y=x;!isroot(y);y=fa[y])q[++r]=fa[y];
for(int i=r;i>=;i--)push(q[i]);
while(!isroot(x)){
if(!isroot(fa[x]))
rotate((get(x)==get(fa[x])?fa[x]:x));
rotate(x);
}
}
inline void access(int x){
for(int y=;x;y=x,x=fa[x]){
splay(x);tr[x][]=y;
if(y)fa[y]=x;
}
}
inline void link(int x,int y){
fa[x]=y;access(y);splay(y);add(y,size[x]);
}
inline void cut(int x){
access(x);splay(x);add(tr[x][],-size[x]);
fa[tr[x][]]=;tr[x][]=;
}
inline void insert(int c){
int p=last,np=++cnt;
last=np;ti[np].l=ti[p].l+;size[np]=;
for(;p&&!ti[p].a[c];p=ti[p].fa)ti[p].a[c]=np;
if(!p){
ti[np].fa=;
link(np,);
}
else{
int q=ti[p].a[c];
if(ti[p].l+==ti[q].l){
ti[np].fa=q;
link(np,q);
}
else{
int nq=++cnt;ti[nq].l=ti[p].l+;
memcpy(ti[nq].a,ti[q].a,sizeof(ti[q].a));
cut(q);
link(nq,ti[q].fa);link(q,nq);link(np,nq);
ti[nq].fa=ti[q].fa;ti[q].fa=ti[np].fa=nq;
for(;p&&ti[p].a[c]==q;p=ti[p].fa)ti[p].a[c]=nq;
}
}
}
inline int query(int len){
int now=;
for(int i=;i<len;i++){
if(ti[now].a[s[i]-'A']){
now=ti[now].a[s[i]-'A'];
}else return ;
}
access(now);splay(now);
return size[now];
}
int main(){
last=cnt=;
int q,mask=,len,res;
scanf("%d%s",&q,s);
len=strlen(s);
for(int i=;i<len;i++)insert(s[i]-'A');
while(q--){
scanf("%s%s",ch,s);
len=strlen(s);res=mask;
for(int i=;i<len;i++){
res=(res*+i)%len;
swap(s[i],s[res]);
}
if(ch[]=='A'){
for(int i=;i<len;i++)insert(s[i]-'A');
}else{
int tmp=query(len);
printf("%d\n",tmp);
mask^=tmp;
}
}
return ;
}

+++++++++++++++++++++++++++++++++++++++++++

+本文作者:luyouqi233。               +

+欢迎访问我的博客:http://www.cnblogs.com/luyouqi233/+

+++++++++++++++++++++++++++++++++++++++++++

BZOJ2555:SubString——题解的更多相关文章

  1. BZOJ2555 SubString【SAM + Link Cut Tree】

    BZOJ2555. SubString 要求在线询问一个串在原串中出现的次数,并且可以在原串末尾添加字符串 如果没有修改的话,考虑建出\(parent\)树之后统计每个\(endpos\)节点的\(r ...

  2. bzoj2555: SubString sam+lct

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

  3. [LeetCode]Longest Palindromic Substring题解(动态规划)

    Longest Palindromic Substring: Given a string s, find the longest palindromic substring in s. You ma ...

  4. [BZOJ2555]SubString LCT+后缀自动机

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

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

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

  6. bzoj2555: SubString

    SAM+LCT维护parent tree版本 虽然说子树维护那套理论需要ETT 不过parent tree的根是固定的,所以用lct加一些奇怪的乱搞就行了 //随手拖个SAM的板子和LCT的板子,然后 ...

  7. BZOJ2555——SubString

    0.题目很短,就不概括了 给你一个字符串init,要求你支持两个操作 (1):在当前字符串的后面插入一个字符串 (2):询问字符串s在当前字符串中出现了几次?(作为连续子串) 你必须在线支持这些操作. ...

  8. [NOIP2015] 子串substring 题解

    [题目描述] 有两个仅包含小写英文字母的字符串A和B.现在要从字符串A中取出k个互不重叠的非空子串,然后把这k个子串按照其在字符串A中出现的顺序依次连接起来得到一个新的字符串,请问有多少种方案可以使得 ...

  9. 2019.03.01 bzoj2555: SubString(sam+lct)

    传送门 题意简述: 要求在线支持两个操作 (1):在当前字符串的后面插入一个字符串 (2):询问字符串s在当前字符串中出现了几次?(作为连续子串) 思路: 考虑用lctlctlct来动态维护samsa ...

随机推荐

  1. pg 与 oracle 比较

    所谓动态引擎,就是说比如有很多张表的Join,原始的做法是一开始就生成好这个执行计划,随后执行,但实际上很多表Join的时候,你一开始生成的那个执行计划很有可能是不对的. 那么动态执行计划就是指它可以 ...

  2. Spark性能优化--数据倾斜调优与shuffle调优

    一.数据倾斜发生的原理 原理:在进行shuffle的时候,必须将各个节点上相同的key拉取到某个节点上的一个task来进行处理,比如按照key进行聚合或join等操作.此时如果某个key对应的数据量特 ...

  3. 远离服务器宕机,腾讯WeTest正式推出服务器深度性能测试服务

    WeTest 导读 随着城市发展趋向智慧化,不仅移动互联网应用正迅速融入出行.金融.医疗.娱乐等传统行业,跟随移动互联网成长起来的,还有用户对应用使用与消费的理性意识. 而在用户不断增加的同时,如何避 ...

  4. Adobe Photoshop CC2018最新教程+某宝店铺装修教程

    PS免费教程,ps淘宝店铺装修教程.该资源为本人从某商网站重金买来,现免费分享给大家,下载地址:百度网盘,https://pan.baidu.com/s/127PjFbGwVVUVce1litHFsw

  5. Matlab2018年最新视频教程视频讲义(包含代码)

    2018年Matlab最新视频教程视频讲义(包含代码),适合初学者入门进阶学习,下载地址:百度网盘, https://pan.baidu.com/s/1w4h297ua6ctzfturQ1791g 内 ...

  6. Unity OBB分包(基础APK+OBB) 与apk签名

    1.OBB (Opaque Binary Blob)文件格式,是安卓游戏通用数据包.在一些大型游戏上较为常见,同时还附以Data文件,亦或是md5.dat文件出现 产生原因:由于某些平台对于apk上传 ...

  7. 树(Tree,UVA 548)

    题目描述: 题目思路: 1.使用数组建树 //递归 2.理解后序遍历和中序遍历,建立左右子树 3.dfs深度搜索找出权重最小的路径 #include <iostream> #include ...

  8. [2017 - 2018 ACL] 对话系统论文研究点整理

    (论文编号及摘要见 [2017 ACL] 对话系统. [2018 ACL Long] 对话系统. 论文标题[]中最后的数字表示截止2019.1.21 google被引次数) 1. Domain Ada ...

  9. Paper Reading - Learning like a Child: Fast Novel Visual Concept Learning from Sentence Descriptions of Images ( ICCV 2015 )

    Link of the Paper: https://arxiv.org/pdf/1504.06692.pdf Innovations: The authors propose the Novel V ...

  10. Some good articles

    https://alligator.io/vuejs/introduction-render-functions/ https://alligator.io/vuejs/vue-jwt-pattern ...