#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef unsigned int ll;
#define maxn 150005
#define p 53
int n,m,root,tot,fa[maxn],son[maxn][],size[maxn];
ll val[maxn],sum[maxn],bin[maxn];
char st[maxn],op[];
void read(int &x){
x=; int f=; char ch;
for (ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') f=-;
for (;isdigit(ch);ch=getchar()) x=x*+ch-''; x*=f;
}
struct SPLAY{
int which(int x){
return son[fa[x]][]==x;
}
void updata(int x){
int ls=son[x][],rs=son[x][];
size[x]=size[ls]+size[rs]+;
sum[x]=sum[rs]+val[x]*bin[size[rs]]+sum[ls]*bin[+size[rs]];
}
int build(int l,int r){
int x; if (l>r) return ; int mid=(l+r)>>;
if (mid==) x=n+,val[x]=;
else if (mid==n+) x=n+,val[x]=;
else x=mid,val[x]=st[x]-'a'; size[x]=;
son[x][]=build(l,mid-),son[x][]=build(mid+,r),updata(x);
if (son[x][]) fa[son[x][]]=x;
if (son[x][]) fa[son[x][]]=x;
return x;
}
void rotata(int x){
int y=fa[x],d=which(x),dd=which(y);
if (fa[y]) son[fa[y]][dd]=x; fa[x]=fa[y];
fa[son[x][d^]]=y,son[y][d]=son[x][d^];
fa[y]=x,son[x][d^]=y,updata(y);
}
void splay(int x,int goal){
while (fa[x]!=goal){
if (fa[fa[x]]==goal) rotata(x);
else if (which(x)==which(fa[x])) rotata(fa[x]),rotata(x);
else rotata(x),rotata(x);
}
if (goal==) root=x; updata(x);
}
int kth(int x){
int y=root,ls,rs; if (!root) return ;
for (;;){
ls=son[y][],rs=son[y][];
if (size[ls]+==x) return y;
else if (size[ls]>=x) y=ls;
else x-=size[ls]+,y=rs;
}
}
bool check(int x,int y,int len){
int t1,t2; t1=kth(x),t2=kth(x+len+);
ll z;splay(t1,),splay(t2,t1),z=sum[son[t2][]];
t1=kth(y),t2=kth(y+len+); splay(t1,),splay(t2,t1);
return z==sum[son[t2][]];
}
}Splay;
void query(int x,int y){
int l=,r,mid,ans=; r=min(tot--x+,tot--y+);
while (l<=r){
mid=(l+r)>>;
if (Splay.check(x,y,mid)==) ans=mid,l=mid+;
else r=mid-;
}printf("%d\n",ans);
}
int main(){
bin[]=; for (int i=;i<=;i++) bin[i]=bin[i-]*p;
scanf("%s",st+),n=strlen(st+);
root=Splay.build(,n+); tot=n+;
read(m);
for (int x,y;m;m--){
scanf("%s",op+);
if (op[]=='Q') read(x),read(y),query(x,y);
else if (op[]=='R') read(x),scanf("%s",op+),x=Splay.kth(x+),Splay.splay(x,),val[x]=op[]-'a',Splay.updata(x);
else{
read(x),scanf("%s",op+),++tot,val[tot]=op[]-'a',size[tot]=;
int t1=Splay.kth(x+),t2=Splay.kth(x+); Splay.splay(t1,),Splay.splay(t2,t1);
fa[tot]=t2,son[t2][]=tot,Splay.updata(t2),Splay.splay(tot,);
}
}
return ;
}

Splay维护,询问时二分答案,Hash判定,我用的是53进制。

splay,二分,Hash。

Hash_1014: [JSOI2008]火星人prefix的更多相关文章

  1. 1014: [JSOI2008]火星人prefix

    1014: [JSOI2008]火星人prefix Time Limit: 10 Sec Memory Limit: 162 MB Description 火星人最近研究了一种操作:求一个字串两个后缀 ...

  2. [BZOJ1014][JSOI2008]火星人prefix

    [BZOJ1014][JSOI2008]火星人prefix 试题描述 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字 ...

  3. BZOJ 1014: [JSOI2008]火星人prefix [splay 二分+hash] 【未完】

    1014: [JSOI2008]火星人prefix Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 6243  Solved: 2007[Submit] ...

  4. 【bzoj1014】[JSOI2008]火星人prefix

    1014: [JSOI2008]火星人prefix Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 6031  Solved: 1917[Submit] ...

  5. BZOJ 1014: [JSOI2008]火星人prefix Splay+二分

    1014: [JSOI2008]火星人prefix 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=1014 Description 火星人 ...

  6. JSOI2008 火星人prefix

    1014: [JSOI2008]火星人prefix Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2918  Solved: 866[Submit][ ...

  7. bzoj 1014: [JSOI2008]火星人prefix hash && splay

    1014: [JSOI2008]火星人prefix Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3154  Solved: 948[Submit][ ...

  8. 求帮看!!!!BZOJ 1014 [JSOI2008]火星人prefix

    1014: [JSOI2008]火星人prefix Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4164  Solved: 1277[Submit] ...

  9. BZOJ 1014: [JSOI2008]火星人prefix( splay + hash )

    用splay维护序列, 二分+hash来判断LCQ.. #include<bits/stdc++.h> using namespace std; typedef unsigned long ...

随机推荐

  1. 【点滴积累,厚积薄发】修改hosts,并刷新dns缓存

    Windows系统下hosts位置 C:\Windows\System32\drivers\etc 修改hosts后,要想马上生效,需要运行命令来刷新DNS缓存:ipconfig /flushdns

  2. SQL Server 百万级数据提高查询速度的方法

    1.应尽量避免在 where 子句中使用!=或<>操作符,否则将引擎放弃使用索引而进行全表扫描. 2.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉 ...

  3. JAVA CDI 学习(1) - @Inject基本用法

    CDI(Contexts and Dependency Injection 上下文依赖注入),是JAVA官方提供的依赖注入实现,可用于Dynamic Web Module中,先给3篇老外的文章,写得很 ...

  4. MyBatis拦截器原理探究

    MyBatis拦截器介绍 MyBatis提供了一种插件(plugin)的功能,虽然叫做插件,但其实这是拦截器功能.那么拦截器拦截MyBatis中的哪些内容呢? 我们进入官网看一看: MyBatis 允 ...

  5. Scala入门之函数

    /** * 函数可以被简单的被认为是包裹了一条或者几条语句的代码体,该代码体接收若干参数,经过代码体处理后返回结果,形如数学中的f(x) = x + 1 * 在Scala中函数式一等公民,可以向变量一 ...

  6. [转]Win2003打不开https的问题

    转自:http://ljl-xyf.iteye.com/blog/2269834 碰到客户做问题是能打开https://www.baidu.com 这个网页 打不开 https://sha256.al ...

  7. [BZOJ1924][Sdoi2010]所托门王的宝藏(缩点+DP)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1924 分析: 首先把传送门作为点建图 这个数据很弱的,没有那种卡你的. 把每行的情况存 ...

  8. Webservice学习

    参考博客1: http://www.cnblogs.com/lzhp/archive/2013/01/13/2858559.html 参考博客2:http://blog.csdn.net/shilei ...

  9. 安装win10

    1.百度win10,看到的大都是雨林木风,ghost等江湖杂牌非原版系统.百度”msdn,我告诉你“进入微软MSDN下载中心(原来还有这么个好地方,以后就从这里下了),下载链接是ed2k格式的链接(e ...

  10. kill 根据PID终止进程

    根据PID终止进程 kill [option] PID-list kill 通过向一个或多个进程发送信号来终止进程.除超级用户外,只有进程的所有者才可以对进程执行kill 参数 PID-list为ki ...