#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. 您的项目引用了最新实体框架;但是,找不到数据链接所需的与版本兼容的实体框架数据库 EF6使用Mysql的技巧

    转载至: http://www.cnblogs.com/Imaigne/p/4153397.html 您的项目引用了最新实体框架:但是,找不到数据链接所需的与版本兼容的实体框架数据库 EF6使用Mys ...

  2. Java多线程总结(二)锁、线程池

    掌握Java中的多线程,必须掌握Java中的各种锁,以及了解Java中线程池的运用.关于Java多线程基础总结可以参考我的这篇博文Java多线程总结(一)多线程基础 转载请注明出处——http://w ...

  3. 安装mint的时候提示:Not compatible with your operating system or architecture: fsevents@1.0.11

    Since fsevents is an API in OS X allows applications to register for notifications of changes to a g ...

  4. java之yield(),sleep(),wait()区别详解

    1.sleep() 使当前线程(即调用该方法的线程)暂停执行一段时间,让其他线程有机会继续执行,但它并不释放对象锁.也就是说如果有synchronized同步快,其他线程仍然不能访问共享数据.注意该方 ...

  5. CoreBluetooth——IOS蓝牙4.0使用心得

    原文链接:http://m.blog.csdn.net/article/details?plg_nld=1&id=51014318&plg_auth=1&plg_uin=1&a ...

  6. Chrome扩展开发之二——Chrome扩展中脚本的运行机制和通信方式

    目录: 0.Chrome扩展开发(Gmail附件管理助手)系列之〇——概述 1.Chrome扩展开发之一——Chrome扩展的文件结构 2.Chrome扩展开发之二——Chrome扩展中脚本的运行机制 ...

  7. Validform表单验证总结

    近期项目里用到了表单的验证,选择了Validform_v5.3.2. 先来了解一下一些基本的参数: 通用表单验证方法:Demo: $(".demoform").Validform( ...

  8. Python 3 与 MySQL 5.6

    主要简单说下Python 3.3搭配MySQL Community Server 5.6的使用.在Python 3系列和MySQL 5.0系列里面下面的代码应该都通用.(没有验证) 准备 python ...

  9. SQLite剖析之C/C++接口

    前言 SQLite3是SQLite一个全新的版本,它虽然是在SQLite2的代码基础之上开发的,但是使用了和之前的版本不兼容的数据库格式和API.SQLite3是为了满足以下的需求而开发的:支持UTF ...

  10. nios II--实验4——按键中断硬件部分

    按键中断 硬件开发 新建原理图 1.打开Quartus II 11.0,新建一个工程,File -> New Project Wizard…,忽略Introduction,之间单击 Next&g ...