我写的代码好像自古以来就是bzoj不友好型的

本地跑的比std快,但是交上去巧妙被卡

答案。。。应该是对的,拍了好久了

  1. #include <bits/stdc++.h>
  2. #define MOD 998244353
  3. #define mid (l+r>>1)
  4. using namespace std;
  5. int n,m,x,y;char ch;
  6. long long mi[];
  7. struct spla
  8. {
  9. int c[][],fa[],ch[],size[],ha[];
  10. int rt,cnt;
  11. void up(int now)
  12. {
  13. size[now]=size[c[now][]]+size[c[now][]]+;
  14. ha[now]=(ha[c[now][]]+mi[size[c[now][]]]*ch[now]%MOD+mi[size[c[now][]]+]*ha[c[now][]]%MOD)%MOD;
  15. }
  16. void rot(int x,int &root)
  17. {
  18. int y=fa[x],k=c[y][]==x;
  19. if(y!=root) c[fa[y]][c[fa[y]][]==y]=x;
  20. else root=x;
  21. fa[x]=fa[y];
  22. fa[y]=x;
  23. fa[c[x][!k]]=y;
  24. c[y][k]=c[x][!k];
  25. c[x][!k]=y;
  26. up(y);up(x);
  27. }
  28. void splay(int x,int &root)
  29. {
  30. for(int y=fa[x];x!=root;rot(x,root),y=fa[x])
  31. if(y!=root)
  32. rot(((c[fa[y]][]==y)^(c[y][]==x))?x:y,root);
  33. }
  34. void add(int x,int y)
  35. {
  36. ch[++cnt]=y;size[cnt]=;ha[cnt]=y;
  37. if(!rt)
  38. {
  39. rt=cnt;
  40. return;
  41. }
  42. if(x==)
  43. {
  44. splay(fin(),rt);
  45. c[rt][]=cnt;fa[cnt]=rt;
  46. return;
  47. }
  48. splay(fin(x),rt);
  49. if(x==n)
  50. c[rt][]=cnt,fa[cnt]=rt;
  51. else
  52. splay(fin(x+),c[rt][]),c[c[rt][]][]=cnt,fa[cnt]=c[rt][];
  53. }
  54. /*
  55. void add(int x,int y)
  56. {
  57. ch[++cnt]=y;size[cnt]=1;ha[cnt]=y;
  58. if(!rt)
  59. {
  60. rt=cnt;
  61. return;
  62. }
  63. int now=rt;
  64. while(1)
  65. {
  66. if(x>size[c[now][0]])
  67. if(c[now][1]) x-=size[c[now][0]]+1,now=c[now][1];
  68. else
  69. {
  70. c[now][1]=cnt;fa[cnt]=now;
  71. splay(cnt,rt);
  72. return;
  73. }
  74. else
  75. if(c[now][0]) now=c[now][0];
  76. else
  77. {
  78. c[now][0]=cnt;fa[cnt]=now;
  79. splay(cnt,rt);
  80. return;
  81. }
  82. }
  83. }*/
  84. int fin(int x)
  85. {
  86. int now=rt;
  87. while(x> || c[now][])
  88. {
  89. if(x==size[c[now][]]+)
  90. break;
  91. if(x>size[c[now][]])
  92. x-=size[c[now][]]+,now=c[now][];
  93. else
  94. now=c[now][];
  95. }
  96. return now;
  97. }
  98. void change(int x,int y)
  99. {
  100. int now=fin(x);
  101. splay(now,rt);
  102. ch[now]=y;
  103. up(now);
  104. }
  105. int hash(int x,int y)
  106. {
  107. if(x== && y==n) return ha[rt];
  108. if(x==)
  109. {
  110. splay(fin(y+),rt);
  111. return ha[c[rt][]];
  112. }
  113. if(y==n)
  114. {
  115. splay(fin(x-),rt);
  116. return ha[c[rt][]];
  117. }
  118. splay(fin(x-),rt);
  119. splay(fin(y+),c[rt][]);
  120. return ha[c[c[rt][]][]];
  121. }
  122. } sp;
  123. inline int read()
  124. {
  125. char ch=getchar();
  126. for(;!isdigit(ch);ch=getchar());
  127. int re=;
  128. bool fl=;
  129. if (ch=='-')
  130. {
  131. re=;
  132. ch=getchar();
  133. }
  134. while (isdigit(ch))
  135. {
  136. re=re*+ch-'';
  137. ch=getchar();
  138. }
  139. return fl?re:-re;
  140. }
  141. inline void write(int re)
  142. {
  143. if (re<)
  144. {
  145. putchar('-');
  146. re=-re;
  147. }
  148. if (re>) write(re/);
  149. putchar(re%+'');
  150. }
  151. void work(int x,int y)
  152. {
  153. if(x>y) swap(x,y);
  154. int l=,r=n-y+;
  155. while(l<r)
  156. if(sp.hash(x,x+mid-)==sp.hash(y,y+mid-)) l=mid+;
  157. else r=mid;
  158. write(l-);puts("");
  159. }
  160. int main()
  161. {
  162. mi[]=;
  163. for(int i=;i<=;i++)
  164. mi[i]=mi[i-]*%MOD;
  165. for(ch=getchar();isalpha(ch);ch=getchar())
  166. sp.add(n,ch-'a'+),++n;
  167. m=read();
  168. for(int i=;i<=m;i++)
  169. {
  170. for(ch=getchar();!isalpha(ch);ch=getchar());
  171. x=read();
  172. if(ch=='Q') y=read();
  173. else
  174. {
  175. char cas=ch;
  176. for(ch=getchar();!isalpha(ch);ch=getchar());
  177. y=ch-'a'+;
  178. ch=cas;
  179. }
  180. if(i==)
  181. int e=;
  182. if(ch=='Q') work(x,y);
  183. else
  184. if(ch=='R')
  185. sp.change(x,y);
  186. else
  187. sp.add(x,y),++n;
  188. }
  189. return ;
  190. }

bzoj1014: [JSOI2008]火星人prefix splay+hash的更多相关文章

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

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

  2. 【BZOJ1014】[JSOI2008]火星人prefix Splay+hash

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

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

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

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

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

  5. 【bzoj1014】[JSOI2008]火星人prefix Splay+Hash+二分

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

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

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

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

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

  8. [BZOJ1014] [JSOI2008] 火星人prefix (splay & 二分答案)

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

  9. [bzoj1014](JSOI2008)火星人 prefix (Splay维护哈希)

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

随机推荐

  1. 【Java】CookieStore 类使用示例

    CookieStore 是 Java API 中用来处理 HTTP 客户端的 Cookie 存储策略的类.psd素材 1. [代码]WebClient.java      01import java. ...

  2. DropDownList(For)

    1.绑定数据源 方法一 Controllers:var users = GetUsers(); var selectList = new SelectList(users, "Value&q ...

  3. TEE&TrustZone

    一.TEE(Trusted Execution Environment) 1 A look back 1)2009 OMTP(Open Mobile Terminal Platform),首次定义了T ...

  4. tflearn 在每一个epoch完毕保存模型

    关键代码:tflearn.DNN(net, checkpoint_path='model_resnet_cifar10', max_checkpoints=10, tensorboard_verbos ...

  5. [原创]java向word模板中填充数据(总结)

    使用过PageOffice动态生成word文档的人都知道,PageOffice可以给word文档的指定位置进行填充,这里我们所说的指定位置在PageOffice的专业术语里面有两个概念,一个叫做数据区 ...

  6. listen 60

    Barbie Exposure May Limit Girls' Career Imagination The ubiquitous Barbie doll: she's been everythin ...

  7. 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 ...

  8. 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 ...

  9. BZOJ1568:[JSOI2008]Blue Mary开公司

    浅谈标记永久化:https://www.cnblogs.com/AKMer/p/10137227.html 题目传送门:https://www.lydsy.com/JudgeOnline/proble ...

  10. Jsp介绍(1)

    JSP(Java Server Pages)是运行在服务端的语言是一种动态网页开发技术它使用JSP标签在HTML网页中插入Java代码.标签通常以<%开头以%>结束.是一种使软件开发者可以 ...