传送门

支持操作:

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)的更多相关文章

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

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

  2. 【BZOJ1251】序列终结者 Splay

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

  3. CODEVS 4655 序列终结者-splay(区间更新、区间翻转、区间最值)

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

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

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

  5. bzoj 1251序列终结者 splay 区间翻转,最值,区间更新

    序列终结者 Time Limit: 20 Sec  Memory Limit: 162 MBSubmit: 4594  Solved: 1939[Submit][Status][Discuss] De ...

  6. bzoj1251 序列终结者(splay)

    人生第一发splay,写得巨丑,最后忘记了push_down以后要将子节点maintain 9k代码不忍直视 #define NDEBUG #include<cstdio> #includ ...

  7. 序列终结者 Splay

    1.注意在 split 和 merge时要特判一下边界, 否则就会出现边界错误的情况. 2.随时都要维护父指针. 3.在更新 maxv 和翻转标记时要判一下左右儿子是否都存在. #include< ...

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

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

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

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

随机推荐

  1. Use Power bi Mobile Show SSRS 2016 Mobile Report;使用 Power BI Mobile 查阅ssrs2016 mobile report

    使用 power bi mobile 查阅 ssrs 2016 mobile report 很简单,以下是IOS客户端的演示. 系统自带了演示数据,包含power bi 的和 ssrs mobile ...

  2. JEECMSv9.3在金蝶Apusic中间件中无法找到首页的问题处理

    在金蝶中间件中启动JEECMS,访问首页显示"页面找不到"信息.而访问后台及其他页面均可正常访问. 经代码查找,发现前台页面的所有地址是通过"com.jeecms.cms ...

  3. 450 Delete Node in a BST 删除二叉搜索树中的结点

    详见:https://leetcode.com/problems/delete-node-in-a-bst/description/ C++: /** * Definition for a binar ...

  4. 自学 iOS - 三十天三十个 Swift 项目 第二天

    继续做仿造着别人的第二个 1.首先下载 一些字体 网上搜索 "造字工房" 2.把下载的相应字体文件放到工程之中,就Ok了 不多说 效果如下 可以下面这个方法 检索项目里面所有的字体 ...

  5. [BZOJ1046][HAOI2007]上升序列 DP+贪心

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1046 我们先求出对于每一个数字作为开头的LCS的长度f[i],最长的f[i]为mxlen. ...

  6. 一个简单的Java代码生成工具—根据数据源自动生成bean、dao、mapper.xml、service、serviceImpl

    目录结构 核心思想 通过properties文件获取数据源—>获取数据表的字段名称.字段类型等—>生成相应的bean实体类(po.model).dao接口(基本的增删改查).mapper. ...

  7. Mysql函数、语句

    一:日期函数: 日期函数: SELECT CURDATE(); # 2018-07-07 SELECT CURTIME(); # 11:28:24 SELECT NOW(); # 2018-07-07 ...

  8. vue2.0 静态prop和动态prop

    动态prop: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <t ...

  9. iTOP-4412开发板网盘资料介绍

    iTOP-4412开发板网盘视频资料内容如下: 01-烧写.编译以及基础知识视频 02-嵌入式Linux 视频 03-iTOP-4412 开发板硬件设计指导视频 04-Android 应用程序视频 0 ...

  10. iOS UI 顶级布局

    状态栏. 导航栏. tabbar. uiviewcontroller视图区域.