#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. 如何将matlab画出的图片保存为要求精度

    · 来源:http://emuch.net/bbs/viewthread.php?tid=2705843 杂志社对投稿图片的分辨率通常有如下要求: TIFF: Colour or greyscale ...

  2. Java7并发编程实战(一) 线程的等待

    试想一个情景,有两个线程同时工作,还有主线程,一个线程负责初始化网络,一个线程负责初始化资源,然后需要两个线程都执行完毕后,才能执行主线程 首先创建一个初始化资源的线程 public class Da ...

  3. CodeSmith操作Access时字段的排序问题

    最近在用CodeSmith操作写ACCESS数据库的代码模版,发现CodeSmith默认的字段顺序与ACCESS中表的字段顺序不一致. 首先在ACCESS数据库中建一个测试表Test,并添加ID.Na ...

  4. 如何优化 FineUI 控件库的性能,减少 80% 的数据上传量!

    在开始正文之前,请帮忙为当前排名前 10 唯一的 .Net 开源软件 FineUI 投一票: 投票地址: https://code.csdn.net/2013OSSurvey/gitop/codevo ...

  5. Loom工具类:Unity3D巧妙处理多线程

    Loom代码不多,只有168行, 然而却具备了子线程运行Action, 子线程与主线程交互的能力! public static Thread RunAsync(Action a) public sta ...

  6. LVS+MYCAT+读写分离+MYSQL主备同步部署手册

    LVS+MYCAT+读写分离+MYSQL主备同步部署手册 1          配置MYSQL主备同步…. 2 1.1       测试环境… 2 1.2       配置主数据库… 2 1.2.1  ...

  7. 【摘抄】将xml注释文档生成网页

    config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath(&quo ...

  8. Android中的各种单位

    px(像素):屏幕上的点.in(英寸):长度单位.mm(毫米):长度单位.pt(磅):1/72英寸.dp(与密度无关的像素):一种基于屏幕密度的抽象单位.在每英寸160点的显示器上,1dp = 1px ...

  9. 屠龙之路_转角遇到服务器大魔王_FourthDay

    Day4:将View打败后,View还送了屠龙团一个信物.于是在今天的旅途中,少年们在遇到View的其他兄弟时,以此信物将他们收于麾下,并借助他们的力量打败了服务器大魔王." Fightin ...

  10. [Bundling and Minification ] 二、绑定的作用

    本篇接上一篇[Bundling and Minification ] 一.如何绑定 Bundling的作用有二,一是合并文件减少资源请求的个数缩短资源请求的时间.二是自动更新到最新js或者css,当合 ...