就第三个操作比较新颖

转化成 在l前插一个点

把r和r+1合并

  1. //By SiriusRen
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. using namespace std;
  6. const int maxn=100005,mod=20130426;
  7. typedef long long ll;
  8. struct Tree{
  9. int fa,ch[2];ll add,mul,size,val;
  10. }tr[666666];
  11. int cnt,root,n,xx,yy,zz;ll ans,t,al;
  12. char op[10];
  13. void push_up(int x){
  14. int lson=tr[x].ch[0],rson=tr[x].ch[1];
  15. tr[x].size=tr[lson].size+tr[rson].size+1;
  16. }
  17. void push_down(int x){
  18. if(!x||(tr[x].mul==1&&tr[x].add==0))return;
  19. int lson=tr[x].ch[0],rson=tr[x].ch[1];
  20. ((tr[lson].add*=tr[x].mul)+=tr[x].add)%=mod;
  21. ((tr[rson].add*=tr[x].mul)+=tr[x].add)%=mod;
  22. ((tr[lson].val*=tr[x].mul)+=tr[x].add)%=mod;
  23. ((tr[rson].val*=tr[x].mul)+=tr[x].add)%=mod;
  24. (tr[lson].mul*=tr[x].mul)%=mod;
  25. (tr[rson].mul*=tr[x].mul)%=mod;
  26. tr[x].mul=1,tr[x].add=0;
  27. }
  28. int build(int l,int r,int father){
  29. if(l>r)return 0;
  30. int pos=++cnt;
  31. tr[pos].size=1,tr[pos].fa=father,tr[pos].mul=1;
  32. if(l==r)return pos;
  33. int mid=(l+r)>>1;
  34. tr[pos].ch[0]=build(l,mid-1,pos);
  35. tr[pos].ch[1]=build(mid+1,r,pos);
  36. push_up(pos);
  37. return pos;
  38. }
  39. void rotate(int p){
  40. int q=tr[p].fa,y=tr[q].fa,x=(tr[q].ch[1]==p);
  41. tr[q].ch[x]=tr[p].ch[!x];tr[tr[q].ch[x]].fa=q;
  42. tr[p].ch[!x]=q;tr[q].fa=p;tr[p].fa=y;
  43. if(y)tr[y].ch[tr[y].ch[1]==q]=p;
  44. push_up(q);
  45. }
  46. void splay(int x,int tp){
  47. for(int y;y=tr[x].fa;rotate(x)){
  48. if(y==tp)break;
  49. if(tr[y].fa!=tp){
  50. if((tr[y].ch[0]==x)^(tr[tr[y].fa].ch[0]==y))rotate(x);
  51. else rotate(y);
  52. }
  53. }push_up(x);
  54. if(!tp)root=x;
  55. }
  56. void dfs(int x){
  57. if(!x)return;
  58. push_down(x);
  59. dfs(tr[x].ch[0]);
  60. if(++al>0)(ans+=t*tr[x].val)%=mod,(t*=xx)%=mod;
  61. dfs(tr[x].ch[1]);
  62. }
  63. int find(int x,int sz){
  64. push_down(x);
  65. if(tr[tr[x].ch[0]].size+1==sz)return x;
  66. else if(tr[tr[x].ch[0]].size>=sz)return find(tr[x].ch[0],sz);
  67. else return find(tr[x].ch[1],sz-tr[tr[x].ch[0]].size-1);
  68. }
  69. int main(){
  70. scanf("%d",&n);
  71. root=build(0,maxn,0);
  72. while(n--){
  73. scanf("%s",op);
  74. if(op[0]=='a'){
  75. scanf("%d%d%d",&xx,&yy,&zz);
  76. int fx=find(root,xx+1),fy=find(root,yy+3);
  77. splay(fx,0),splay(fy,fx);
  78. (tr[tr[fy].ch[0]].add+=zz)%=mod,(tr[tr[fy].ch[0]].val+=zz)%=mod;
  79. push_up(fy),push_up(fx);
  80. }
  81. else if(op[3]=='x'){
  82. scanf("%d%d",&xx,&yy);
  83. int fx=find(root,yy+1),fy=find(root,yy+4);
  84. splay(fx,0),splay(fy,fx);
  85. push_down(fx),push_down(fy),push_down(tr[fy].ch[0]);
  86. int now1=tr[fy].ch[0],now2=tr[now1].ch[0]+tr[now1].ch[1];
  87. tr[now1].val+=tr[now2].val,tr[now1].size=1;
  88. tr[now2].fa=tr[now1].ch[0]=tr[now1].ch[1]=0;
  89. push_up(fy),push_up(fx);
  90. fx=find(root,xx+1),fy=find(root,xx+2);
  91. splay(fx,0),splay(fy,fx);tr[fy].ch[0]=++cnt;
  92. tr[cnt].size=1,tr[cnt].fa=fy,tr[cnt].mul=1;
  93. push_up(fy),push_up(fx);
  94. }
  95. else if(op[0]=='q'){
  96. scanf("%d",&xx),ans=0,t=1,al=-1,dfs(root),printf("%lld\n",ans);
  97. }
  98. else{
  99. scanf("%d%d%d",&xx,&yy,&zz);
  100. int fx=find(root,xx+1),fy=find(root,yy+3);
  101. splay(fx,0),splay(fy,fx);
  102. (tr[tr[fy].ch[0]].mul*=zz)%=mod,(tr[tr[fy].ch[0]].val*=zz)%=mod;
  103. (tr[tr[fy].ch[0]].add*=zz)%=mod,push_up(fy),push_up(fx);
  104. }
  105. }
  106. }

BZOJ 3323 splay维护序列的更多相关文章

  1. BZOJ 1251 Splay维护序列

    思路: splay维护序列的裸题 啊woc调了一天 感谢yzy大佬的模板-- //By SiriusRen #include <cstdio> #include <cstring&g ...

  2. BZOJ 3729 splay维护DFS序+博弈论

    思路: 这像是 阶梯Nim之类的东西 我们 直接把sg函数 设成mod(L+1)的 一棵子树 向下的奇数层上的石子xor起来 就是答案 有加点和改值的操作 就splay维护一下 //By Sirius ...

  3. BZOJ 3223 Tyvj 1729 文艺平衡树 | Splay 维护序列关系

    题解: 每次reverse(l,r) 把l-1转到根,r+1变成他的右儿子,给r+1的左儿子打个标记就是一次反转操作了 每次find和dfs输出的时候下放标记,把左儿子和右儿子换一下 记得建树的时候建 ...

  4. 【模板】splay维护序列

    题目大意:维护一个长度为 N 的序列,支持单点插入,单点询问. 注意事项如下: build 函数中要记得初始化 fa. 插入两个端点值. 代码如下 #include <bits/stdc++.h ...

  5. bzoj 1014 splay维护hash值

    被后缀三人组虐了一下午,写道水题愉悦身心. 题很裸,求lcq时二分下答案就行了,写的不优美会被卡时. (写题时精神恍惚,不知不觉写了快两百行...竟然调都没调就A了...我还是继续看后缀自动机吧... ...

  6. 洛谷 P2023 BZOJ 1798 [AHOI2009]维护序列

    题目描述 老师交给小可可一个维护数列的任务,现在小可可希望你来帮他完成. 有长为N的数列,不妨设为a1,a2,…,aN .有如下三种操作形式: (1)把数列中的一段数全部乘一个值; (2)把数列中的一 ...

  7. bzoj 1798 Seq 维护序列seq —— 线段树

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1798 这题还4A... 注意:cnt 从1开始:各种模 p:乘法标记初始值是 1:可能乘 0 ...

  8. Letters Removing CodeForces - 899F (线段树维护序列)

    大意: 给定字符串, 每次删除一段区间的某种字符, 最后输出序列. 类似于splay维护序列. 每次删除都会影响到后面字符的位置 可以通过转化为查询前缀和=k来查找下标. #include <i ...

  9. [BZOJ 1500] 维护序列

    Link: BZOJ 1500 传送门 Solution: 可能平衡树维护序列的所有操作都在这了吧…… 对序列的维护$fhq treap$和$Splay$都能做 有几个注意点: 1.维护序列时始终记得 ...

随机推荐

  1. 给html里面的class添加一个判断语句,判断当前class是否显示(vue)

    当我们想判断这个class是否出现时,其实有很多方法, 我这个是做了一个选项卡,当点击的时候navTitle的值和循环的item的值相同时class就等于borderbottom, 这样我们点击的图层 ...

  2. Django02 Django基础知识

    一.内容回顾 1.web应用程序 2.HTTP协议 a.http协议特性 b.http请求格式 c.http响应格式 3.wsgiref模块 4.Django下载与简单应用 a.Django简介(MT ...

  3. Brain Network (hard) CodeForces - 690C 简单倍增 + 一些有趣的推导

    Code: #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ...

  4. 安装和启动Elasticseach

    1.在windows上安装和启动Elasticseach 1.安装JDK,至少1.8.0_73以上版本,java -version2.下载和解压缩Elasticsearch安装包.Elasticsea ...

  5. appium不能获取webview内容的解决办法

    在用appium对小猿搜题app进行自动化测试时,准备用page_source打印出文章的xml内容 但是发现只能打印出外部结构内容,实际的文章内容却没有显示 截图如下 查询之后,得知需要通过cont ...

  6. el7上的开机自动执行脚本

    /etc/rc.local 是 /etc/rc.d/rc.local的软连接 默认, /etc/rc.local 是有可执行权限的, 只要 给 /etc/rc.d/rc.local 加上可执行权限即可 ...

  7. Vue学习之路第十一篇:为页面元素设置class类样式

    1.class为页面元素的一个属性,通过前面第五篇的内容可知,操作属性需要使用到v-bind指定(也可简写为 :). 2.先来看一个简单的页面样式内容: <!DOCTYPE html> & ...

  8. 【JavaScript框架封装】实现一个类似于JQuery的缓存框架的封装

    // 缓存框架 (function (xframe) { /** * 实现了缓存框架的临时存储功能(内存存储) * @type {{data: Array, get: (function(*): *) ...

  9. Project Euler 21 Distinct primes factors( 整数因子和 )

    题意: 记d(n)为n的所有真因数(小于n且整除n的正整数)之和. 如果d(a) = b且d(b) = a,且a ≠ b,那么a和b构成一个亲和数对,a和b被称为亲和数. 例如,220的真因数包括1. ...

  10. [SPOJ1716] GSS3 - Can you answer these queries III

    线段树操作. 维护一个区间最大连续子段和,左最大连续子段和,右最大连续子段和即可. 最后不知道怎么搞,query的时候返回了个结构体. #include <cstdio> #include ...