我只是一个存模板的,详细的请看这里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. 提高在Xcode上的工作效率

    对于在Xcode上提高工作效率,内功在这不提,对于外力,我将它分为三类: 工具.快捷键和小技巧.主要获得的路径是通过平时积累和看 WWDC12 上的 Session 402:Working Effic ...

  2. Linq查询满足条件记录集

    通过linq查询datatable数据集合满足条件的数据集 1.首先定义查询字段的变量,比方深度 string strDepth=查询深度的值: var dataRows = from datarow ...

  3. Mac 安装配置Mysql

    Mac下安装配置Mysql By 白熊花田(http://blog.csdn.net/whiterbear) 转载需注明出处,谢谢. 下载安装 去官网下载Community版本号的mysql安装文件. ...

  4. js:深入继承

    /**  * js实现继承:  * 1.基于原型链的方式  * 2.基于伪造的方式  * 3.基于组合的方式  */ 一.基于原型链的方式 function Parent(){   this.pv = ...

  5. PHP_EOL是什么意思?

      PHP_EOL 代表php的换行符, 这个变量会根据平台而变, 在windows下会是/r/n, 在linux下是/n, 在mac下是/r             文章来源:刘俊涛的博客 地址:h ...

  6. mt-checklist 的 bug 解疑 及 防止 this 指针偏移

    1.今天在使用 mt-checklist 时,发现 绑定 change 方法后,第一次点击返回的值为 空数组 <template> <div id="app"&g ...

  7. 实现TextView中link的点击效果

    朋友们,你们在TextView处理link的时候是不是一直被苦逼的android默认的方式困扰?每次点击link的时候,点击效果是整个textview来响应.非常烂吧?原因就不多赘述了. 那么以下这个 ...

  8. selector的button选中处理问题

    1.背景介绍 在做Android项目开发的时候,有时我们须要对button做一些特殊的处理,比方button点击的时候会有一个动画的效果,实际上就是几张图片在短时间的切换.再比方有时候我们须要对界面的 ...

  9. Excel表格数据导入Mysql数据库的方法

    1.使用Navicat 连接需要导入的数据库. 2.excel 列的名字最好和数据库的名字一致,便于我们直观的查看好理解.   第一步,先创建好表,和准备好对应的excel文件.在Navicat 中选 ...

  10. android arcmenu

    http://www.kankanews.com/ICkengine/archives/129193.shtml