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. 【log4net】- 日志使用教程

    一.log4net简介: 1. Log4net的优点: 几乎所有的大型应用都会有自己的用于跟踪调试的API.因为一旦程序被部署以后,就不太可能再利用专门的调试工具了.然而一个管理员可能需要有一套强大的 ...

  2. P1404 平均数

    题目描述 给一个长度为n的数列,我们需要找出该数列的一个子串,使得子串平均数最大化,并且子串长度>=m. 输入输出格式 输入格式: N+1行, 第一行两个整数n和m 接下来n行,每行一个整数a[ ...

  3. [COGS 2089.] 平凡的测试数据 带权并查集

    差点就撸上LCT了....... 带权并查集就是在并查集的基础上稍作修改,我的用穿址实现的有人用记录原父亲来实现. #include<cstdio> #define N 300010 us ...

  4. Spring事务只对运行时异常回滚

    我们在使用Spring时候一般都知道事务在遇到异常的时候会回滚,岂不知Spring的事务默认只有在发生运行时异常即:RunTimeException时才会发生事务,如果一个方法抛出Exception或 ...

  5. [lucene系列笔记3]用socket把lucene做成一个web服务

    上一篇介绍了用lucene建立索引和搜索,但是那些都只是在本机上运行的,如果希望在服务器上做成web服务该怎么办呢? 一个有效的方法就是用socket通信,这样可以实现后端与前端的独立,也就是不管前端 ...

  6. SQLNET跟踪tnsping过程

    原文地址:SQLNET跟踪tnsping过程 作者:yingyifeng306 sqlnet是oracle提供的与网络层面交互的一个工具,比如如何解析客户端发起的连接,如何对客户端发起的连接进行辨别, ...

  7. 群联MPALL(Rel) 7F V5.03.0A-DL07量产工具 PS2251-07(PS2307)

    前言:U盘被写保护,真的很醉人啊~~      群联MPALL是一款群联PS2251系列主控量产修复工具,本版本支持PS2251-67.PS2251-68.PS2251-02.PS2251-03.PS ...

  8. org.apache.http.conn.HttpHostConnectException: Connection to xxx refused.

    if you are using emulator to run your app for local server. mention the local ip as 10.0.2.2 and hav ...

  9. idea 从远程仓库导入git项目

    File--new --Project from vision control -- git 输入远程仓库地址 即可.

  10. 矩阵快速幂&T1

    T1 知识储备 在写这一题之前,我们首先要了解矩阵乘法(我就是因为不懂弄了好久...) 矩阵的运算()-----(信息学奥赛一本通之提高篇) 矩阵的加法减法是十分简单的,就是把2个矩阵上对应的位置相加 ...