#include <iostream>
 #include <cstring>
 #include <algorithm>
 #include <cstdio>
 #include <queue>
 #define oo 1000000000
 #define lc(x) son[x][0]
 #define rc(x) son[x][1]
 using namespace std;
 int i,j,k,n,m,s,t,ans;
 ];
 struct node
 {
     int set,rever;
 } tag[];
 ][];
 ];
 ];
 ];
 ];
 ];
 ];
 ];
 ];
 queue <int> q;
 int root,cnt,pos;
 void update(int x)
 {
     size[x] = size[lc(x)]+size[rc(x)]+;
     tsum[x] = tsum[lc(x)]+tsum[rc(x)]+key[x];
     lmax[x] = max(lmax[lc(x)],tsum[lc(x)]+key[x]+lmax[rc(x)]);
     rmax[x] = max(rmax[rc(x)],tsum[rc(x)]+key[x]+rmax[lc(x)]);
     tmax[x] = max(max(tmax[lc(x)],tmax[rc(x)]),lmax[rc(x)]+key[x]+rmax[lc(x)]);
 }
 void Round(int x)
 {
     swap(lc(x),rc(x));
     swap(lmax[x],rmax[x]);
 }
 void build(int l,int r,int &x)
 {
     if (l>r)
     {
         x = ;
         return;
     }
     if (l==r)
     {
         if (!q.empty())
         {
             x = q.front();
             q.pop();
         } else x = ++cnt;
         tag[x].rever = ;
         tag[x].;
         key[x] = tsum[x] = tmax[x] = a[l];
         lmax[x] = rmax[x] = max(,a[l]);
         size[x] = ;
         lc(x) = rc(x) = ;
         return;
     }
     ;
     if (!q.empty())
     {
         x = q.front();
         q.pop();
     } else x = ++cnt;
     key[x] = a[mid];
     tag[x].rever = ;
     tag[x].;
     lc(x) = rc(x) = ;
     build(l,mid-,lc(x));
     build(mid+,r,rc(x));
     ) fa[lc(x)] = x;
     ) fa[rc(x)] = x;
     update(x);
 }
 void pushdown(int x)
 {
     )
     {
         tag[x].rever = ;
         tag[lc(x)].rever ^= ;
         tag[rc(x)].rever ^= ;
         Round(lc(x));
         Round(rc(x));
     }
     )
     {
         )
         {
             tag[lc(x)].set = tag[x].set;
             key[lc(x)] = tag[x].set;
             tsum[lc(x)] = tag[x].set*size[lc(x)];
             ) tmax[lc(x)] = lmax[lc(x)] = rmax[lc(x)] = tsum[lc(x)];
             else
             {
                 tmax[lc(x)] = tag[x].set;
                 lmax[lc(x)] = rmax[lc(x)] = ;
             }
         }
         )
         {
             tag[rc(x)].set = tag[x].set;
             key[rc(x)] = tag[x].set;
             tsum[rc(x)] = tag[x].set*size[rc(x)];
             ) tmax[rc(x)] = lmax[rc(x)] = rmax[rc(x)] = tsum[rc(x)];
             else
             {
                 tmax[rc(x)] = tag[x].set;
                 lmax[rc(x)] = rmax[rc(x)] = ;
             }
         }
         tag[x].;
     }
 }
 int find(int x,int k)
 {
     pushdown(x);
     ==k) return x;
     else if (size[lc(x)]>=k) return find(lc(x),k);
     );
 }
 void rotate(int x)
 {
     int y = fa[x],z = fa[y],w = lc(y)==x;
     pushdown(y);
     pushdown(x);
     fa[son[x][w]] = y;son[y][w^] = son[x][w];
     fa[x] = z;) son[z][rc(z)==y] = x;
     son[x][w] = y;fa[y] = x;
     update(y);
     update(x);
 }
 void splay(int x,int s)
 {
     pushdown(x);
     while (fa[x]!=s)
     {
         int y = fa[x],z = fa[y];
         if (z!=s) rotate(lc(z)==y^lc(y)==x?x:y);
         rotate(x);
     }
     update(x);
     ) root = x;
 }
 void insert(int pos)
 {
     int z;
     build(,n,z);
     int x = find(root,pos);
     );
     splay(x,);
     splay(y,root);
     lc(y) = z;
     fa[z] = y;
     update(y);
     update(x);
 }
 void del(int x)
 {
     ) return;
     del(lc(x));
     q.push(x);
     del(rc(x));
 }
 void erase(int pos,int n)
 {
     );
     int y = find(root,pos+n);
     splay(x,);
     splay(y,root);
     del(lc(y));
     lc(y) = ;
     update(y);
     update(x);
 }
 int main()
 {
     scanf("%d%d",&n,&m);
     a[] = a[n+] = -oo;
     tmax[] = -oo;
     ;i<=n+;i++) scanf("%d",&a[i]);
     build(,n+,root);
     while (m--)
     {
         ];
         scanf();
         ]=='I')
         {
             scanf("%d%d",&pos,&n);
             ;i<=n;i++)
             scanf("%d",&a[i]);
             insert(pos+);
         } ]=='D')
         {
             scanf("%d%d",&pos,&n);
             erase(pos+,n);
         } ]==]=='K')
         {
             int c;
             scanf("%d%d%d",&pos,&n,&c);
             int x = find(root,pos);
             );
             splay(x,);
             splay(y,root);
             tag[lc(y)].set = c;
             key[lc(y)] = c;
             tsum[lc(y)] = c*size[lc(y)];
             ) tmax[lc(y)] = lmax[lc(y)] = rmax[lc(y)] = tsum[lc(y)];
             else
             {
                 tmax[lc(y)] = c;
                 lmax[lc(y)] = rmax[lc(y)] = ;
             }
             update(y);
             update(x);
         } ]=='R')
         {
             scanf("%d%d",&pos,&n);
             int x = find(root,pos);
             );
             splay(x,);
             splay(y,root);
             tag[lc(y)].rever ^= ;
             Round(lc(y));
             update(y);
             update(x);
         } ]=='G')
         {
             scanf("%d%d",&pos,&n);
             int x = find(root,pos);
             );
             splay(x,);
             splay(y,root);
             printf("%d\n",tsum[lc(y)]);
         } else printf("%d\n",tmax[root]);
     }
     ;
 }

BZOJ1500 维修数列

【splay模板】的更多相关文章

  1. bzoj 1588 splay模板题

    用晚自习学了一下splay模板,没想象中那么难,主要是左旋和右旋可以简化到一个函数里边,减少代码长度... #include<iostream> #include<cstdio> ...

  2. COJ 1002 WZJ的数据结构(二)(splay模板)

    我的LCC,LCT,Splay格式终于统一起来了... 另外..这个形式的Splay是标准的Splay(怎么鉴别呢?看Splay函数是否只传了一个变量node就行),刘汝佳小白书的Splay写的真是不 ...

  3. Splay 模板

    Splay 模板 struct SplayTree{ const static int maxn = 1e5 + 15; int ch[maxn][2] , key[maxn] , s[maxn] , ...

  4. [luogu3369/bzoj3224]普通平衡树(splay模板、平衡树初探)

    解题关键:splay模板题整理. 如何不加入极大极小值?(待思考) #include<cstdio> #include<cstring> #include<algorit ...

  5. BZOJ1588 [HNOI2002]营业额统计 splay模板

    1588: [HNOI2002]营业额统计 Time Limit: 5 Sec  Memory Limit: 162 MB Submit: 16189  Solved: 6482 [Submit][S ...

  6. 文艺平衡树(splay模板)

    题干:splay模板,要求维护区间反转. splay是一种码量小于treap,但支持排名,前驱后继等treap可求的东西,也支持区间反转的平衡树. 但是有两个坏处: 1.splay常数远远大于trea ...

  7. [洛谷P3391] 文艺平衡树 (Splay模板)

    初识splay 学splay有一段时间了,一直没写...... 本题是splay模板题,维护一个1~n的序列,支持区间翻转(比如1 2 3 4 5 6变成1 2 3 6 5 4),最后输出结果序列. ...

  8. bzoj 1208 splay模板题2

    自己yy了找前驱和后继,学了学怎么删除...(反正就是练模板) #include<iostream> #include<cstdio> #include<cstring& ...

  9. 【BZOJ 3196】二逼平衡树 线段树套splay 模板题

    我写的是线段树套splay,网上很多人写的都是套treap,然而本蒟蒻并不会treap 奉上sth神犇的模板: //bzoj3196 二逼平衡树,支持修改某个点的值,查询区间第k小值,查询区间某个值排 ...

  10. 【BZOJ 3188】【Coci 2011】Upit Splay模板题

    转啊转终于转出来了,然而我的模板跟陈竞潇学长的模板一模一样,还是太弱啊,第一次用指针. #include<cstdio> #include<cstring> #include& ...

随机推荐

  1. 支持ASP.NET WebService

    ASP.NET WebService默认返回的数据格式是XML,但也能返回JSON格式. 如何让MiniUI组件支持ASP.NET WebService? 只需要: 1) 引用miniui-webse ...

  2. Programming in Lua读书笔记

         Lua的长处之一就是可以通过新类型和函数来扩展其功能.动态类型检查最大限度允许多态出现,并自动简化调用内存管理的接口,因为这样不需要关心谁来分配内存谁来释放内存,也不必担心数据溢出.高级函数 ...

  3. GPUImage实现摄像头暂停

    GPUImage相信很多开发者都用过,其本身也是十分简单易用,因此对于GPUImage的基本用法不再赘述. 最近在使用GPUImage时要实现摄像时暂停和继续的功能,但GPUImage本身并没有提供相 ...

  4. 迪杰斯特拉(dijkstra)算法的简要理解和c语言实现(源码)

    迪杰斯特拉(dijkstra)算法:求最短路径的算法,数据结构课程中学习的内容. 1 . 理解 算法思想::设G=(V,E)是一个带权有向图,把图中顶点集合V分成两组,第一组为已求出最短路径的顶点集合 ...

  5. PSP个人(观众界面)

    需求:作为一个观众,我希望了解某一场比赛的比分,以便了解赛况.(满意条件:精确到每一局的结果比分) 需求分析:实现查询数据库中每一局的分数并用界面显示. 生成设计文档: 运用三层架构,实现软件的基本功 ...

  6. Nginx配置文件(nginx.conf)配置详解(2)

    Nginx的配置文件nginx.conf配置详解如下: user nginx nginx ; Nginx用户及组:用户 组.window下不指定 worker_processes 8; 工作进程:数目 ...

  7. mysql中修改view的definer

    我常用的工具是navicat,但是修改definer不能用工具,只能用命令行: 数据库迁移到其他服务器上,会报definer错误,修改view的definer方法如下(比如把definer改为本地的, ...

  8. 主机WIFI网络环境下,Linux虚拟机网络设置

    在主机使用WIFI网络环境下,怎么样进行虚拟机静态ip设置和连接互联网呢,原理什么太麻烦,另类的网络共享而已: 1.其实简单将网络连接模式设置成NAT模式即可. 2.虚拟网络编辑器依旧是桥接模式,选择 ...

  9. const关键字也许该被替换为readonly

    只读的变量,其值在编译时不能被使用,因为编译器在编译时不知道其存储的内容. const修饰的只读变量 const  int   Max = 100: int  Array[Max] ; c文件中,编译 ...

  10. iOS中UIImageView的填充模式

    UIImageView的填充模式 属性名称 imageV.contentMode枚举属性: @"UIViewContentModeScaleToFill", // 拉伸自适应填满整 ...