#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. BZOJ 3295 【Cqoi2011】 动态逆序对

    Description 对于序列\(A\),它的逆序对数定义为满足\(i<j\),且\(A_i>A_j\)的数对\((i,j)\)的个数.给\(1\)到\(n\)的一个排列,按照某种顺序依 ...

  2. WP老杨解迷:可知评论系统还能勾搭用户呢

    玩家可以忍受任何游戏内的磨难,但偏偏不能忍受游戏外的挫折,这个游戏外可不是因为系统原因怒摔手机的义举,更加不是线下见面互炫菊花转投阵营的冲动,有可能是登录的瞬间,那小小的提示,又出问题了,登录不上去, ...

  3. [转]WampServer localhost 图标不显示解决办法

    FROM : http://blog.warmcolor.net/2011/11/03/wampserver-localhost-%E5%9B%BE%E6%A0%87%E4%B8%8D%E6%98%B ...

  4. win8.1环境下安装arduino驱动问题解决方案

    1. Windows 键+ R, 输入 shutdown.exe /r /o /f /t 00 2.此时电脑会自动重启,进入一下画面,选择Troubleshoot (转载请注明原处:http://ww ...

  5. 记、基于react-router的单页应用

    现在用react写单页应用基本上都是用react-router做前端路由了吧!最近在使用react-router的过程中遇到了不少问题,在这里总结一下. 浏览器url react-router默认提供 ...

  6. SVN——配置和安装

    SVN安装步骤: 所有安装文件下载地址:http://pan.baidu.com/s/1bocNTDl 一.安装01----VisualSVN-Server-3.4.2-x64.msi 文件 直接下一 ...

  7. linux svn搭建

    1 安装: yum install subversion 2 查看svn安装信息: rpm -ql subversion 3 创建svn根目录: svnserve -d -r /svn 4 进入/sv ...

  8. Vmware player 12

    免费版的虚拟机Vmware,体积小.运行快速... 官方下载界面 下载地址: http://yunpan.cn/cm5smywVvqS8V  访问密码 35ac 官方下载:点击下载

  9. webpack入坑之旅(六)配合vue-router实现SPA

    这是一系列文章,此系列所有的练习都存在了我的github仓库中vue-webpack,在本人有了新的理解与认识之后,会对文章有不定时的更正与更新.下面是目前完成的列表: webpack入坑之旅(一)不 ...

  10. ELK 的好文章连接

    http://www.wklken.me/posts/2016/05/24/elk-mysql-slolog.html   处理mysql慢查询日志 http://www.wklken.me/post ...