我只是一个存模板的,详细的请看这里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. 【springcloud】使用@FEIGNCLIENT时,报JAVA.LANG.NOCLASSDEFFOUNDERROR: FEIGN/FEIGN$BUILDER错

    引用地址:http://www.cnblogs.com/ellacan/p/8822374.html 错误信息: Caused by: java.lang.ClassNotFoundException ...

  2. 【maven】架包下载失败,maven引入架包失败,pom文件未报错,但是引用的注解找不到

    出现这种问题 看到这个jar包显示是unkown,不知道版本,所以这样的解决方法就是 1.先查看maven设置是使用的自定义的仓库还是默认的仓库 2.删除掉你引用的jar包下载失败的文件夹 3.然后重 ...

  3. Kaggle的Outbrain点击预测比赛分析

    https://yq.aliyun.com/articles/293596 https://www.kaggle.com/c/outbrain-click-prediction https://www ...

  4. SpringMVC同时支持多视图(JSP,Velocity,Freemarker等)的一种思路实现

    在基于SpringMVC的项目中有时需要同时使用多种视图格式,如jsp,velocity及freemarker等,通过不同的请求路径配置规则,映射到不同的视图文件.下面我提供一种思路,通过视图模板文件 ...

  5. npm升级所有可更新包

    使用npm管理node的包,可以使用npm update <name>对单个包升级,对于npm的版本大于 2.6.1,可以使用命令: npm install -g 升级全局的本地包. 对于 ...

  6. SPFA 求带负权的单源最短路

    int spfa_bfs(int s) { ///s表示起点. queue <int> q; memset(d,0x3f,sizeof(d)); ///d数组中存下的就是最短路径(存在的话 ...

  7. update tableView contenSize

    NSIndexPath *messageIndexPath = [NSIndexPath indexPathForRow:afterRowCount-1 inSection:0];    [self. ...

  8. eclipse工具栏sdk和avd图标

    打开菜单Window -> Customize Perspective -> Command Groups Availability -> 勾选Android SDK and AVD ...

  9. Active Directory的LDAP协议与DN(Distinguished Name)详解

    前言 光copy几段代码的文章没什么意思,本章上最基础的代码,主要是为了从编程方面聊LDAP和DN,其它的后面聊,一步步慢慢来吧. Active Directory编程须知 1.域控服务器: Wind ...

  10. gridcontrol复选框功能实现(超具体)

    博主这几天就准备离职了,以后不再做.Net开发.因此这应该是我写的最后一篇关于dev控件的博文.既然是最后一篇,那就写的具体一些.画个圆满的省略号...... 本文介绍gridcontrol怎样实现复 ...