[codevs4655] 序列终结者(Splay)
支持操作:
1.区间加
2.区间翻转
3.区间求最大值
splay模板
注意:update 里更新 max 时需要取 3 个值的 Max
别忘了各种边界讨论
——代码
#include <cstdio>
#define ls son[now][0]
#define rs son[now][1] const int MAXN = , INF = 2e9;
int n, m, root, cnt;
int a[MAXN], size[MAXN], key[MAXN], add[MAXN], max[MAXN], rev[MAXN], f[MAXN], son[MAXN][]; inline void swap(int &x, int &y)
{
x ^= y ^= x ^= y;
} inline int Max(int x, int y)
{
return x > y ? x : y;
} inline int get(int x)
{
return x == son[f[x]][];
} inline void update(int now)
{
if(now)
{
size[now] = ;
if(ls) size[now] += size[ls];
if(rs) size[now] += size[rs]; max[now] = key[now];
if(ls) max[now] = Max(max[now], max[ls]);
if(rs) max[now] = Max(max[now], max[rs]);
}
} inline void pushdown(int now)
{
if(rev[now])
{
swap(ls, rs);
if(ls) rev[ls] ^= ;
if(rs) rev[rs] ^= ;
rev[now] = ;
}
if(add[now])
{
if(ls) add[ls] += add[now], key[ls] += add[now], max[ls] += add[now];
if(rs) add[rs] += add[now], key[rs] += add[now], max[rs] += add[now];
add[now] = ;
}
} inline void build(int x, int y, int fa, int &now)
{
if(x > y) return;
int mid = (x + y) >> ;
now = ++cnt;
f[now] = fa;
build(x, mid - , now, ls);
build(mid + , y, now, rs);
update(now);
} inline void rotate(int x)
{
pushdown(f[x]);
pushdown(x);
int old = f[x], oldf = f[old], wh = get(x); son[old][wh] = son[x][wh ^ ];
f[son[old][wh]] = old; if(oldf) son[oldf][old == son[oldf][]] = x;
f[x] = oldf; son[x][wh ^ ] = old;
f[old] = x; update(old);
update(x);
} inline void splay(int x, int to)
{
for(int fa; (fa = f[x]) != to; rotate(x))
if(f[fa] != to)
rotate(get(x) ^ get(fa) ? x : fa);
if(!to) root = x;
} inline int find(int x)
{
int now = root;
while()
{
pushdown(now);
if(x <= size[ls]) now = ls;
else
{
x -= size[ls];
if(x == ) return now;
x--;
now = rs;
}
}
} int main()
{
int i, k, x, y, v;
scanf("%d %d", &n, &m);
a[] = -INF, a[n + ] = -INF;
build(, n + , , root);
for(i = ; i <= m; i++)
{
scanf("%d %d %d", &k, &x, &y);
x = find(x);
y = find(y + );
splay(x, );
splay(y, x);
if(k == )
{
scanf("%d", &v);
add[son[son[root][]][]] += v;
max[son[son[root][]][]] += v;
key[son[son[root][]][]] += v;
update(son[root][]);
update(root);
}
else if(k == ) rev[son[son[root][]][]] ^= ;
else printf("%d\n", max[son[son[root][]][]]);
}
return ;
}
[codevs4655] 序列终结者(Splay)的更多相关文章
- BZOJ 1251: 序列终结者 [splay]
1251: 序列终结者 Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 3778 Solved: 1583[Submit][Status][Discu ...
- 【BZOJ1251】序列终结者 Splay
一道模板题,一直没发现自己的快速读入读不了负数,我竟然能活到现在真是万幸. #include <iostream> #include <cstdio> #define inf ...
- CODEVS 4655 序列终结者-splay(区间更新、区间翻转、区间最值)
4655 序列终结者 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 大师 Master 题解 题目描述 Description 网上有许多题,就是给定一个序列,要 ...
- [bzoj1251]序列终结者——splay
题目大意 网上有许多题,就是给定一个序列,要你支持几种操作:A.B.C.D.一看另一道题,又是一个序列 要支持几种操作:D.C.B.A.尤其是我们这里的某人,出模拟试题,居然还出了一道这样的,真是没技 ...
- bzoj 1251序列终结者 splay 区间翻转,最值,区间更新
序列终结者 Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 4594 Solved: 1939[Submit][Status][Discuss] De ...
- bzoj1251 序列终结者(splay)
人生第一发splay,写得巨丑,最后忘记了push_down以后要将子节点maintain 9k代码不忍直视 #define NDEBUG #include<cstdio> #includ ...
- 序列终结者 Splay
1.注意在 split 和 merge时要特判一下边界, 否则就会出现边界错误的情况. 2.随时都要维护父指针. 3.在更新 maxv 和翻转标记时要判一下左右儿子是否都存在. #include< ...
- BZOJ 1251 序列终结者(Splay)
题目大意 网上有许多题,就是给定一个序列,要你支持几种操作:A.B.C.D.一看另一道题,又是一个序列要支持几种操作:D.C.B.A.尤其是我们这里的某人,出模拟试题,居然还出了一道这样的,真是没技术 ...
- 【BZOJ】1251: 序列终结者(splay)
http://www.lydsy.com/JudgeOnline/problem.php?id=1251 不行..为什么写个splay老是犯逗,这次又是null的mx没有赋值-maxlongint.. ...
随机推荐
- 转-iOS 动画总结----UIView动画
来自:http://blog.csdn.net/huifeidexin_1/article/details/7597868/ 1.概述 UIKit直接将动画集成到UIView类中,实现简单动画的创建过 ...
- OpenCV2.4.9 + Ubuntu15.04配置
为了run Car-Detection安装了OpenCV. 基本上就照着这个弄下来: ubuntu14.04 + OpenCV2.4.9 配置方法 1. 安装openCV 所需依赖库或软件: s ...
- 配置Oracle网络服务
Oracle网络服务是什么呢? Oracle网络服务是客户端访问数据库服务器端才需要配置的,也就是说,你的Oracle数据库没有装在你自己的电脑上,你需要去访问别人电脑上的Oracle数据库,那么你就 ...
- vue采坑及较好的文章汇总
1:父子组件传动态传值 https://www.cnblogs.com/daiwenru/p/6694530.html -----互传数据基本流程 https://blog.csdn.net/qq_ ...
- mysql 忘记密码 登陆+修改密码
step1: 苹果->系统偏好设置->最下边点mysql 在弹出页面中 关闭mysql服务(点击stop mysql server) step2: 进入终端输入:cd /usr/local ...
- Hadoop YARN学习之组件功能简述(3)
Hadoop YARN学习之组件功能简述(3) 1. YARN的三大组件功能简述: ResourceManager(RM)是集群的资源的仲裁者, 它有两部分:一个可插拔的调度器和一个Applicati ...
- APP崩溃处理
以前经常遇到APP内部异常情况下的Exception,最初是通过try catch这样的方式处理:但是APP上线后,用户在特地的情况下触发 了某些Exception,当然这些Exception从理论和 ...
- Int 1的实现过程 (一)
闲话少说,直奔主题,首先OD载入一个程序,然后执行一下单步(调试器会将TF置1) 此时,CPU会在基于当前线程上下文的环境中,进入int 1的中断门,也就是KiTrap01 kd> !idt - ...
- 迅为i.MX6UL核心板ARMCortex-A7单核NXP飞思卡尔工控行业Imx6核心板
iMX6UL核心板小巧精致,尺寸仅38mm*42mm:CPU型号iMX6UL@ 528MHz ARM Cortex-A7架构 :内存:512M DDR :存储:8G EMMC,低功耗,性能强大,性价比 ...
- emil 的使用
摘抄自别人 RFC882文档规定了如何编写一封简单的邮件(纯文本邮件),一封简单的邮件包含邮件头和邮件体两个部分,邮件头和邮件体之间使用空行分隔. 邮件头包含的内容有: from字段 --用于指明发 ...