bzoj1014: [JSOI2008]火星人prefix splay+hash
我写的代码好像自古以来就是bzoj不友好型的
本地跑的比std快,但是交上去巧妙被卡
答案。。。应该是对的,拍了好久了
- #include <bits/stdc++.h>
- #define MOD 998244353
- #define mid (l+r>>1)
- using namespace std;
- int n,m,x,y;char ch;
- long long mi[];
- struct spla
- {
- int c[][],fa[],ch[],size[],ha[];
- int rt,cnt;
- void up(int now)
- {
- size[now]=size[c[now][]]+size[c[now][]]+;
- ha[now]=(ha[c[now][]]+mi[size[c[now][]]]*ch[now]%MOD+mi[size[c[now][]]+]*ha[c[now][]]%MOD)%MOD;
- }
- void rot(int x,int &root)
- {
- int y=fa[x],k=c[y][]==x;
- if(y!=root) c[fa[y]][c[fa[y]][]==y]=x;
- else root=x;
- fa[x]=fa[y];
- fa[y]=x;
- fa[c[x][!k]]=y;
- c[y][k]=c[x][!k];
- c[x][!k]=y;
- up(y);up(x);
- }
- void splay(int x,int &root)
- {
- for(int y=fa[x];x!=root;rot(x,root),y=fa[x])
- if(y!=root)
- rot(((c[fa[y]][]==y)^(c[y][]==x))?x:y,root);
- }
- void add(int x,int y)
- {
- ch[++cnt]=y;size[cnt]=;ha[cnt]=y;
- if(!rt)
- {
- rt=cnt;
- return;
- }
- if(x==)
- {
- splay(fin(),rt);
- c[rt][]=cnt;fa[cnt]=rt;
- return;
- }
- splay(fin(x),rt);
- if(x==n)
- c[rt][]=cnt,fa[cnt]=rt;
- else
- splay(fin(x+),c[rt][]),c[c[rt][]][]=cnt,fa[cnt]=c[rt][];
- }
- /*
- void add(int x,int y)
- {
- ch[++cnt]=y;size[cnt]=1;ha[cnt]=y;
- if(!rt)
- {
- rt=cnt;
- return;
- }
- int now=rt;
- while(1)
- {
- if(x>size[c[now][0]])
- if(c[now][1]) x-=size[c[now][0]]+1,now=c[now][1];
- else
- {
- c[now][1]=cnt;fa[cnt]=now;
- splay(cnt,rt);
- return;
- }
- else
- if(c[now][0]) now=c[now][0];
- else
- {
- c[now][0]=cnt;fa[cnt]=now;
- splay(cnt,rt);
- return;
- }
- }
- }*/
- int fin(int x)
- {
- int now=rt;
- while(x> || c[now][])
- {
- if(x==size[c[now][]]+)
- break;
- if(x>size[c[now][]])
- x-=size[c[now][]]+,now=c[now][];
- else
- now=c[now][];
- }
- return now;
- }
- void change(int x,int y)
- {
- int now=fin(x);
- splay(now,rt);
- ch[now]=y;
- up(now);
- }
- int hash(int x,int y)
- {
- if(x== && y==n) return ha[rt];
- if(x==)
- {
- splay(fin(y+),rt);
- return ha[c[rt][]];
- }
- if(y==n)
- {
- splay(fin(x-),rt);
- return ha[c[rt][]];
- }
- splay(fin(x-),rt);
- splay(fin(y+),c[rt][]);
- return ha[c[c[rt][]][]];
- }
- } sp;
- inline int read()
- {
- char ch=getchar();
- for(;!isdigit(ch);ch=getchar());
- int re=;
- bool fl=;
- if (ch=='-')
- {
- re=;
- ch=getchar();
- }
- while (isdigit(ch))
- {
- re=re*+ch-'';
- ch=getchar();
- }
- return fl?re:-re;
- }
- inline void write(int re)
- {
- if (re<)
- {
- putchar('-');
- re=-re;
- }
- if (re>) write(re/);
- putchar(re%+'');
- }
- void work(int x,int y)
- {
- if(x>y) swap(x,y);
- int l=,r=n-y+;
- while(l<r)
- if(sp.hash(x,x+mid-)==sp.hash(y,y+mid-)) l=mid+;
- else r=mid;
- write(l-);puts("");
- }
- int main()
- {
- mi[]=;
- for(int i=;i<=;i++)
- mi[i]=mi[i-]*%MOD;
- for(ch=getchar();isalpha(ch);ch=getchar())
- sp.add(n,ch-'a'+),++n;
- m=read();
- for(int i=;i<=m;i++)
- {
- for(ch=getchar();!isalpha(ch);ch=getchar());
- x=read();
- if(ch=='Q') y=read();
- else
- {
- char cas=ch;
- for(ch=getchar();!isalpha(ch);ch=getchar());
- y=ch-'a'+;
- ch=cas;
- }
- if(i==)
- int e=;
- if(ch=='Q') work(x,y);
- else
- if(ch=='R')
- sp.change(x,y);
- else
- sp.add(x,y),++n;
- }
- return ;
- }
bzoj1014: [JSOI2008]火星人prefix splay+hash的更多相关文章
- bzoj1014: [JSOI2008]火星人prefix splay+hash+二分
Description 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字符予以标号:序号: 1 2 3 4 5 6 7 ...
- 【BZOJ1014】[JSOI2008]火星人prefix Splay+hash
[BZOJ1014][JSOI2008]火星人prefix Description 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个 ...
- BZOJ 1014: [JSOI2008]火星人prefix( splay + hash )
用splay维护序列, 二分+hash来判断LCQ.. #include<bits/stdc++.h> using namespace std; typedef unsigned long ...
- BZOJ 1014 [JSOI2008]火星人prefix (Splay + Hash + 二分)
1014: [JSOI2008]火星人prefix Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 8112 Solved: 2569[Submit] ...
- 【bzoj1014】[JSOI2008]火星人prefix Splay+Hash+二分
题目描述 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字符予以标号:序号: 1 2 3 4 5 6 7 8 9 10 ...
- BZOJ1014[JSOI2008]火星人prefix(splay维护hash)
Description 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字符予以标号:序号: 1 2 3 4 5 6 7 ...
- BZOJ1014: [JSOI2008]火星人prefix(splay 二分 hash)
题意 题目链接 Sol 一眼splay + 二分hash,不过区间splay怎么写来着呀 试着写了两个小时发现死活不对 看了一下yyb的代码发现自己根本就不会splay.... // luogu-ju ...
- [BZOJ1014] [JSOI2008] 火星人prefix (splay & 二分答案)
Description 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字符予以标号:序号: 1 2 3 4 5 6 7 ...
- [bzoj1014](JSOI2008)火星人 prefix (Splay维护哈希)
Description 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀. 比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字符予以标号:序号: 1 2 3 4 5 6 ...
随机推荐
- 【Java】CookieStore 类使用示例
CookieStore 是 Java API 中用来处理 HTTP 客户端的 Cookie 存储策略的类.psd素材 1. [代码]WebClient.java 01import java. ...
- DropDownList(For)
1.绑定数据源 方法一 Controllers:var users = GetUsers(); var selectList = new SelectList(users, "Value&q ...
- TEE&TrustZone
一.TEE(Trusted Execution Environment) 1 A look back 1)2009 OMTP(Open Mobile Terminal Platform),首次定义了T ...
- tflearn 在每一个epoch完毕保存模型
关键代码:tflearn.DNN(net, checkpoint_path='model_resnet_cifar10', max_checkpoints=10, tensorboard_verbos ...
- [原创]java向word模板中填充数据(总结)
使用过PageOffice动态生成word文档的人都知道,PageOffice可以给word文档的指定位置进行填充,这里我们所说的指定位置在PageOffice的专业术语里面有两个概念,一个叫做数据区 ...
- listen 60
Barbie Exposure May Limit Girls' Career Imagination The ubiquitous Barbie doll: she's been everythin ...
- leetcode 104 Maximum Depth of Binary Tree(DFS)
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- POJ3237 Tree(树剖+线段树+lazy标记)
You are given a tree with N nodes. The tree’s nodes are numbered 1 through N and its edges are numbe ...
- BZOJ1568:[JSOI2008]Blue Mary开公司
浅谈标记永久化:https://www.cnblogs.com/AKMer/p/10137227.html 题目传送门:https://www.lydsy.com/JudgeOnline/proble ...
- Jsp介绍(1)
JSP(Java Server Pages)是运行在服务端的语言是一种动态网页开发技术它使用JSP标签在HTML网页中插入Java代码.标签通常以<%开头以%>结束.是一种使软件开发者可以 ...