题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1014

因为涉及到增加和修改,所以后缀数组就被pass掉了,想到的就是平衡树维护hash值,查询的时候就是二分相同的长度来比较,修改就是删除再增加。

这里使用的是无旋Treap

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int ull;
const int maxn = ;
int Siz[maxn], ls[maxn], rs[maxn], pos[maxn], val[maxn], root, cnt;
ull Hash[maxn], w[maxn];
inline void up(int x) {
Siz[x] = Siz[ls[x]] + Siz[rs[x]] + ;
w[x] = w[ls[x]] * Hash[Siz[rs[x]] + ] + Hash[Siz[rs[x]]] * val[x] + w[rs[x]];
}
inline void split_size(int x, int siz, int &A, int &B) {
if (x == )return (void)(A = B = );
if (siz <= Siz[ls[x]])
B = x, split_size(ls[x], siz, A, ls[x]);
else
A = x, split_size(rs[x], siz - Siz[ls[x]] - , rs[x], B);
up(x);
}
inline int Merge(int A, int B) {
if (A == || B == )return A | B;
int ans;
if (pos[A] > pos[B])ans = A, rs[A] = Merge(rs[A], B);
else ans = B, ls[B] = Merge(A, ls[B]);
up(ans);
return ans;
}
inline void insert(int x, char v) {
int A, B;
split_size(root, x, A, B);
cnt++;
w[cnt] = val[cnt] = v - 'a' + ;
Siz[cnt] = ;
pos[cnt] = rand();
root = Merge(Merge(A, cnt), B);
}
inline void Delete(int x) {
int A, B, C, D;
split_size(root, x, A, B);
split_size(A, x - , C, D);
D = Merge(ls[D], rs[D]);
root = Merge(Merge(C, D), B);
}
inline ull query(int l, int r) {
int A, B, C, D;
ull ans;
split_size(root, l - , A, B);
split_size(B, r - l + , C, D);
ans = w[C];
root = Merge(A, Merge(C, D));
return ans;
}
inline bool check(int x, int y, int len) {
return query(x, x + len - ) == query(y, y + len - );
}
inline int read() {
int x = , f = ; char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -;
for (; isdigit(c); c = getchar()) x = x * + c - ''; return x * f;
}
inline char cread() {
char c = getchar();
for (; !isalpha(c); c = getchar()); return c;
}
inline void reads(string& s) {
char c = getchar();
for (; !isalpha(c); c = getchar()); s = " ";
for (; isalpha(c); c = getchar()) s += c;
}
string s;
int main() {
reads(s);
int n = s.size() - , m;
m = read();
Hash[] = ;
for (int i = ; i < maxn; i++)
Hash[i] = Hash[i - ] * ;
for (int i = ; i <= n; i++)
insert(i, s[i]);
while (m--) {
char opt;
int x, y;
opt = cread();
if (opt == 'Q') {
x = read(), y = read();
int l = , r = min(n - x, n - y) + , ans;
while (l <= r) {
int mid = l + r >> ;
if (check(x, y, mid)) {
ans = mid;
l = mid + ;
}
else
r = mid - ;
}
printf("%d\n", ans);
}
else if (opt == 'R') {
x = read(), opt = cread();
Delete(x);
insert(x - , opt);
}
else {
x = read(), opt = cread();
n++;
insert(x, opt);
}
}
return ;
}

[Bzoj1014][JSOI2008]火星人prefix(无旋Treap&hash)的更多相关文章

  1. BZOJ1014 JSOI2008 火星人prefix 【非旋转Treap】*

    BZOJ1014 JSOI2008 火星人prefix Description 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符 ...

  2. [BZOJ1014][JSOI2008]火星人prefix

    [BZOJ1014][JSOI2008]火星人prefix 试题描述 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字 ...

  3. 2018.06.28 BZOJ1014 [JSOI2008]火星人prefix(非旋treap+hash)

    [JSOI2008]火星人prefix Time Limit: 10 Sec Memory Limit: 162 MB Submit: 8951 Solved: 2860 Description 火星 ...

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

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

  5. Jewel Magic UVA - 11996 || bzoj1014: [JSOI2008]火星人prefix

    Jewel Magic UVA - 11996 这是一道用splay/非旋treap做的题(这里用的是非旋treap) 1/2/3是splay/非旋treap的常规操作.对于操作4,可以用哈希法求LC ...

  6. bzoj1014: [JSOI2008]火星人prefix splay+hash+二分

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

  7. BZOJ1014[JSOI2008]火星人prefix(splay维护hash)

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

  8. BZOJ1014: [JSOI2008]火星人prefix(splay 二分 hash)

    题意 题目链接 Sol 一眼splay + 二分hash,不过区间splay怎么写来着呀 试着写了两个小时发现死活不对 看了一下yyb的代码发现自己根本就不会splay.... // luogu-ju ...

  9. bzoj1014: [JSOI2008]火星人prefix(splay+hash+二分)

    题目大意:一个字符串三个操作:①求两个后缀的LCP②插入一个字符③修改一个字符. 前几天刚学了hash+二分求lcp,就看到这题. 原来splay还能这么用?!原来splay模板这么好写?我以前写的s ...

随机推荐

  1. Vue+elementui 实现复杂表头和动态增加列的二维表格

    先上完成的效果图:列是根据查询结果增加的 数据格式: 表头的数据取出: data.data.forEach(element => { this.thead.push({ 品名: element. ...

  2. windwos下nginx 配置https并http强制跳转https

    windwos下nginx  配置https并http强制跳转https 一.首先配置证书文件 申请证书文件,这里就不做详细过程了,直接看证书文件结果. 这是两个证书的关键文件 打开ngxin下con ...

  3. java.lang.NoClassDefFoundError: javax/transaction/Synchronization

    转自:https://blog.csdn.net/andsionok/article/details/68490848 今天在整合ssh框架中 程序报告Java.lang.NoClassDefFoun ...

  4. iOS开发-retain/assign/strong/weak/copy/mutablecopy/autorelease区别

    依旧本着尊重原创和劳动者的原则,将地址先贴在前面: http://www.cnblogs.com/nonato/archive/2013/11/28/3447162.html,作者Nonato 以下内 ...

  5. goland使用:导入一个github开源项目tidb

    概要:在windos下的IDEA 的go语言的编辑器 goland的使用,导入github上面的开源项目. 问题: 下载好goland之后,open project打开一个下载好的githubhub项 ...

  6. selenium下拉一个框内的滚动条

    js='document.getElementsByClassName("route-tree")[0].scrollTop=10000'

  7. less:避免编译

    .box { width: ~"calc(300px - 30px)"; } 编译成css .box { width: calc(300px - 30px); } importan ...

  8. Ansible笔记(2)---常用模块之文件操作

    一.copy模块 1.1作用: copy模块是将ansible主机上的文件拷贝到远程受控主机 1.2常用参数: src参数 :用于指定需要copy的文件或目录. dest参数 :用于指定文件将被拷贝到 ...

  9. [sqlmap 源码阅读] heuristicCheckSqlInjection 探索式注入

    上面是探索式注入时大致调用过程,注入 PAYLOAD 1.)("'(.((.  , 数据库报错,通过报错信息获取网站数据库类型(kb.dbms),并将保存报错(lasterrorpage). ...

  10. Rabbit MQ项目例子

    地址链接: https://blog.csdn.net/cartoonmiao/article/details/51920766