1014

思路:

  平衡树+二分答案+hash;

  好了懂了吧。

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 2000005 int ch[maxn][],key[maxn],f[maxn],root,size[maxn];
int n,m,tot; long long ha[maxn],mi[maxn]; char ai[maxn]; inline void in(int &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'') Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
} inline bool getson(int now)
{
return ch[f[now]][]==now;
} inline void updata(int now)
{
size[now]=,ha[now]=;
if(ch[now][]) size[now]+=size[ch[now][]],ha[now]+=ha[ch[now][]];
ha[now]+=key[now]*mi[size[now]-];
if(ch[now][]) ha[now]+=ha[ch[now][]]*mi[size[now]],size[now]+=size[ch[now][]];
} inline void rotate(int now,int &to)
{
int fa=f[now],ffa=f[fa];bool pos=getson(now);
ch[fa][pos]=ch[now][pos^];
if(ch[fa][pos]) f[ch[fa][pos]]=fa;
if(to==fa) to=now;
else ch[ffa][getson(fa)]=now;
ch[now][pos^]=fa,f[fa]=now,f[now]=ffa;
updata(fa),updata(now);
} void splay(int now,int &to)
{
while(now!=to)
{
int fa=f[now],ffa=f[fa];
if(fa!=to)
{
if(ch[fa][]==now^ch[ffa][]==fa) rotate(now,to);
else rotate(now,to);
}rotate(now,to);
}
} void find(int p,bool pos)
{
int now=root;
while()
{
if(size[ch[now][]]>=p) now=ch[now][];
else
{
p-=size[ch[now][]];
if(p==)
{
if(pos) splay(now,root);
else splay(now,ch[root][]);
return ;
}
else p--,now=ch[now][];
}
}
} void insert(int p,int ci)
{
find(p,true),find(p+,false);
ch[ch[root][]][]=++tot;
key[tot]=ci,size[tot]=,f[tot]=ch[root][],ha[tot]=ci;
updata(ch[root][]),updata(root);
} int tree_build(int l,int r,int fa)
{
int now=l+r>>;key[now]=ai[now],f[now]=fa;
if(now>l) ch[now][]=tree_build(l,now-,now);
if(now<r) ch[now][]=tree_build(now+,r,now);
updata(now);return now;
} long long hash_ci(int p,int len)
{
find(p,true),find(p+len+,false);
return ha[ch[ch[root][]][]];
} int main()
{
mi[]=;
for(int i=;i<=;i++) mi[i]=mi[i-]*27LL;
scanf("%s",ai+),tot=strlen(ai+)+;
for(int i=;i<=tot-;i++) ai[i]=ai[i]-'a'+;
root=tree_build(,tot,);
in(m);char op[];int u,v;
for(;m--;)
{
scanf("%s",op);
if(op[]=='Q')
{
in(u),in(v);
if(u>v) swap(u,v);
int l=,r=tot-v-,ans=;
while(l<=r)
{
int mid=l+r>>;
if(hash_ci(u,mid)==hash_ci(v,mid)) ans=mid,l=mid+;
else r=mid-;
}
printf("%d\n",ans);
}
else if(op[]=='R')
{
in(u),scanf("%s",op);
find(u+,true),key[root]=op[]-'a'+,updata(root);
}
else
{
in(u),scanf("%s",op);
insert(u+,(int)(op[]-'a'+));
}
}
return ;
}

AC日记——[JSOI2008]火星人prefix bzoj 1014的更多相关文章

  1. 1014: [JSOI2008]火星人prefix - BZOJ

    Description 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字符予以标号:序号: 1 2 3 4 5 6 7 ...

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

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

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

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

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

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

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

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

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

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

  7. BZOJ 1014 [JSOI2008]火星人prefix (Splay + Hash + 二分)

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

  8. 1014: [JSOI2008]火星人prefix

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

  9. bzoj千题计划106:bzoj1014 [JSOI2008]火星人prefix

    http://www.lydsy.com/JudgeOnline/problem.php?id=1014 两个后缀的最长公共前缀:二分+hash 带修改带插入:splay维护 #include< ...

随机推荐

  1. http短连接大量time wait解决方案

    tcp连接是网络编程中最基础的概念,基于不同的使用场景,我们一般区分为“长连接”和“短连接”,长短连接的优点和缺点这里就不详细展开了,有心的同学直接去google查询,本文主要关注如何解决tcp短连接 ...

  2. Football Games(思维题)

    Problem Description A mysterious country will hold a football world championships---Abnormal Cup, at ...

  3. bootsrap 上传插件fileinput 简单使用

    1.安装 下载fileinput文件,载入对应的css+js文件,如下: <link href="css/bootstrap.min.css" rel="style ...

  4. [剑指Offer] 27.字符串的排列

    [思路]从第一位开始,判断每一位字符的所有可能性,依此递归. class Solution { public: void PermutationHelp(vector<string> &a ...

  5. [洛谷P3937]Changing

    题目大意:有 $n$ 盏灯环形排列,顺时针依次标号为 $1\cdots n$.初始时刻为 $0$ ,初始时刻第 $i$ 盏灯的亮灭 $a_i$, $0$ 表示灭, $1$ 表示亮.下一时刻每盏灯的亮灭 ...

  6. CCmdUI

    原文链接地址:http://blog.csdn.net/luicha/article/details/6771185 CCmdUI是一个只被使用于ON_UPDATECOMMAND_UI消息的响应函数中 ...

  7. 【CF MEMSQL 3.0 E. Desk Disorder】

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  8. watch用法小记

    By francis_hao    Jun 30,2017   watch:周期性的执行一个一个程序,并全屏显示输出 概述 watch [options] command   描述 watch重复的运 ...

  9. 五分钟搞懂Vuex

    这段时间一直在用vue写项目,vuex在项目中也会依葫芦画瓢使用,但是总有一种朦朦胧胧的感觉.于是决定彻底搞懂它. 看了一下午的官方文档,以及资料,才发现vuex so easy! 作为一个圈子中的人 ...

  10. css3 新旧伸缩盒的异同

    由于不需要理会IE浏览器,伸缩盒(flexible box)移动端开发中非常好用! 工作中使用APICLOUD开发手机App,老板要求兼容到安卓2.3(新版的需要安卓4.4以上),所以一直使用的是旧版 ...