我只是一个存模板的,详细的请看这里http://blog.csdn.net/whai362/article/details/47298133

题目链接:http://www.codevs.cn/problem/4655/

 #include <cstdio>
#include <cstring>
#include <cctype>
#include <cmath>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef long long LL;
const int INF = 2e9 + 1e8; const int MOD = 1e9 + ;
const double eps = 0.0000000001; #define MSET(a, b) memset(a, b, sizeof(a)) const int maxn = 1e6 + ;
int max(int a, int b, int c)
{
return max(a, max(b, c));
} struct SplayTree
{
struct Node
{
int son[], big, val, lazy, sz;
bool rev;
void init(int _val)
{
val = big = _val;
sz = ;
lazy = rev = son[] = son[] = ;
}
} T[maxn];
int root, fa[maxn];
void pushup(int i)
{
T[i].big=T[i].val,T[i].sz=;
if(T[i].son[])
{
T[i].big=max(T[i].big,T[T[i].son[]].big);
T[i].sz+=T[T[i].son[]].sz;
}
if(T[i].son[])
{
T[i].big=max(T[i].big,T[T[i].son[]].big);
T[i].sz+=T[T[i].son[]].sz;
}
}
void pushdown(int i)
{
if (i == )
return;
if (T[i].lazy)
{
for (int k = ; k < ; k++)
{
if (T[i].son[k])
{
T[T[i].son[k]].lazy += T[i].lazy;
T[T[i].son[k]].val += T[i].lazy;
T[T[i].son[k]].big += T[i].lazy;
}
}
T[i].lazy = ;
}
if (T[i].rev)
{
for (int k = ; k < ; k++)
if (T[i].son[k])
T[T[i].son[k]].rev ^= ;
swap(T[i].son[], T[i].son[]);
T[i].rev = ;
}
}
/** 旋转操作
* 传入x,旋转x与x的父亲这两个节点;
*/
void rotate(int x, int d)
{
int y = fa[x], z = fa[y];
T[y].son[!d] = T[x].son[d], fa[T[x].son[d]] = y;
T[x].son[d] = y, fa[y] = x;
T[z].son[T[z].son[] == y] = x, fa[x] = z;
pushup(y);
}
void splay(int x, int goal)
{
if (x == goal)
return;
while (fa[x] != goal)
{
int y = fa[x], z = fa[y];
pushdown(z), pushdown(y), pushdown(x);
int dirx = (T[y].son[] == x), diry = (T[z].son[] == y);
if (z == goal)
rotate(x, dirx);
else
{
if (dirx == diry)
rotate(y, diry);
else
rotate(x, dirx);
rotate(x, diry);
}
}
pushup(x);
if (goal == )
root = x;
}
/**
* select(pos) 返回第pos+1个元素;
*/
int Select(int pos)
{
int u = root;
pushdown(u);
while (T[T[u].son[]].sz != pos)
{
if (pos < T[T[u].son[]].sz)
u = T[u].son[];
else
{
pos = pos - ( + T[T[u].son[]].sz);
u = T[u].son[];
}
pushdown(u);
}
return u;
}
void update(int l, int r, int val)
{
int x = Select(l - ), y = Select(r + );
splay(x, );
splay(y, x);
T[T[y].son[]].val += val;
T[T[y].son[]].big += val;
T[T[y].son[]].lazy += val;
}
void turn(int l, int r)
{
int x = Select(l - ), y = Select(r + );
splay(x, );
splay(y, x);
T[T[y].son[]].rev ^= ;
}
int query(int l, int r)
{
int x = Select(l - ), y = Select(r + );
splay(x, );
splay(y, x);
return T[T[y].son[]].big;
}
int build(int L, int R)
{
if (L > R)
return ;
if (L == R)
return L;
int mid = (L + R) >> , sL, sR;
T[mid].son[] = sL = build(L, mid - );
T[mid].son[] = sR = build(mid + , R);
fa[sL] = fa[sR] = mid;
pushup(mid);
return mid;
} void init(int n)
{
T[].init(-INF), T[n + ].init(-INF);
for (int i = ; i <= n + ; i++)
T[i].init();
root = build(, n + ), fa[root] = ;
fa[] = , T[].son[] = root, T[].sz = ;
}
} re; int main()
{
int n, m;
scanf("%d%d", &n, &m);
re.init(n);
for (int i = , a, b, c, d; i < m; i++)
{
scanf("%d", &a);
if (a == )
{
scanf("%d%d%d", &b, &c, &d);
re.update(b, c, d);
}
else if (a == )
{
scanf("%d%d", &b, &c);
re.turn(b, c);
}
else
{
scanf("%d%d", &b, &c);
printf("%d\n", re.query(b, c));
}
}
return ;
} /**************************************************/
/** Copyright Notice **/
/** writer: wurong **/
/** school: nyist **/
/** blog : http://blog.csdn.net/wr_technology **/
/**************************************************/

Splay模板(序列终结者)的更多相关文章

  1. splay树 序列终结者

    /* 4655 序列终结者  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 大师 Master 题解       题目描述 Description 网上有许多题,就是给定一个序 ...

  2. 【BZOJ1251】序列终结者 Splay

    一道模板题,一直没发现自己的快速读入读不了负数,我竟然能活到现在真是万幸. #include <iostream> #include <cstdio> #define inf ...

  3. 1251. 序列终结者【平衡树-splay】

    Description 网上有许多题,就是给定一个序列,要你支持几种操作:A.B.C.D.一看另一道题,又是一个序列 要支持几种操作:D.C.B.A.尤其是我们这里的某人,出模拟试题,居然还出了一道这 ...

  4. [bzoj1251]序列终结者——splay

    题目大意 网上有许多题,就是给定一个序列,要你支持几种操作:A.B.C.D.一看另一道题,又是一个序列 要支持几种操作:D.C.B.A.尤其是我们这里的某人,出模拟试题,居然还出了一道这样的,真是没技 ...

  5. BZOJ 1251: 序列终结者 [splay]

    1251: 序列终结者 Time Limit: 20 Sec  Memory Limit: 162 MBSubmit: 3778  Solved: 1583[Submit][Status][Discu ...

  6. BZOJ 1251 序列终结者(Splay)

    题目大意 网上有许多题,就是给定一个序列,要你支持几种操作:A.B.C.D.一看另一道题,又是一个序列要支持几种操作:D.C.B.A.尤其是我们这里的某人,出模拟试题,居然还出了一道这样的,真是没技术 ...

  7. 【BZOJ】1251: 序列终结者(splay)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1251 不行..为什么写个splay老是犯逗,这次又是null的mx没有赋值-maxlongint.. ...

  8. bzoj1251 序列终结者(Splay Tree+懒惰标记)

    Description 网上有许多题,就是给定一个序列,要你支持几种操作:A.B.C.D.一看另一道题,又是一个序列 要支持几种操作:D.C.B.A.尤其是我们这里的某人,出模拟试题,居然还出了一道这 ...

  9. 「BZOJ1251」序列终结者 (splay 区间操作)

    题面: 1251: 序列终结者 Time Limit: 20 Sec  Memory Limit: 162 MBSubmit: 5367  Solved: 2323[Submit][Status][D ...

随机推荐

  1. 【hibernate postgresql】注解@TypeDef/@Enumerated/数据库字段gender为枚举类型,从前台接受到实体后进行保存报错:org.postgresql.util.PSQLException: ERROR: column "gender" is of type gender but expression is of type character varying

    数据库字段gender为枚举类型,从前台接受到实体后进行保存报错:org.postgresql.util.PSQLException: ERROR: column "gender" ...

  2. Mac下export生效

    在Terminal下用export PS1=XXX   修改完后,本次生效,但是重新启动Teminal后又恢复到默认格式.如何才能永久保存自定义的提示符格式呢? 1,~下面本来没有 .bash_pro ...

  3. oralce中相关的概念整理

    [数据库名]  概念:就是一个数据库的标识,作用等同于我们的身份证的作用,假设一台机器上安装了多个数据库,那么每一个数据库都会有一个数据库名称相应,这些数据库名称在数据库被创建的时候,数据库名称也会被 ...

  4. 基于GPU加速的三维空间分析【转】

    基于GPU加速的三维空间分析 标签:supermap地理信息系统gisit 文:李凯 随着三维GIS 的快速发展和应用普及,三维空间分析技术以其应用中的实用性成为当前GIS技术研究的热点领域.面对日益 ...

  5. 写一个dup2功能同样的函数,不能调用 fcntl 函数,而且要有出错处理

    实现的时候用到系统原来的dup函数 // mydup2.c // 2015/08/17 Lucifer Zhang version1.0 // write my own dup2 function / ...

  6. C中的预编译编译链接

        http://ke.qq.com/webcourse/index.html#course_id=67888&term_id=100058920&taid=13934591901 ...

  7. HDU ACM 1073 Online Judge -&gt;字符串水题

    分析:水题. #include<iostream> using namespace std; #define N 5050 char a[N],b[N],tmp[N]; void Read ...

  8. [RFC] Simplifying kernel configuration for distro issues

    http://lwn.net/Articles/507276/ From: Linus Torvalds <torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b-A ...

  9. Android gdb so

    gdb debug an android application 1.gdb 要有gdbserver 一般模拟器默认装有gdbserver,如2.3.3的模拟器,看一下有没有: D:\Develope ...

  10. Kubernetes对象之Service

    系列目录 通过ReplicaSet来创建一组Pod来提供具有高可用性的服务.虽然每个Pod都会分配一个单独的Pod IP,然而却存在如下两问题: Pod IP仅仅是集群内可见的虚拟IP,外部无法访问. ...