传送门

支持操作:

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 ;
}

最新文章

  1. [LeetCode] Remove Duplicates from Sorted Array II 有序数组中去除重复项之二
  2. [ASP.NET MVC] ASP.NET Identity登入技术应用
  3. Spring MVC 学习总结(五)——校验与文件上传
  4. 蓝牙--对象交换协议(OBEX)
  5. Spring学习 Ioc篇(一 )
  6. Inno_setup制作升级包必须面临的几个问题
  7. 制作LiveCD
  8. Linux学习笔记22——线程属性(转)
  9. OC与JS的交互(iOS与H5混编)
  10. UML和模式应用3:迭代和进化式分析和设计案例研究
  11. Flask 目录
  12. 170704、springboot编程之CommandLineRunner
  13. JS中typeof和instanceof的用法和区别
  14. 语义分析:C语言表达式的语法树生成——Python实现
  15. 如何清理Macbook垃圾文件
  16. mac appstore应用下载失败,不能更新等等问题,都可以解决
  17. Spark RDD API详解之:Map和Reduce
  18. SqlServer报错:System.Data.SqlClient.SqlException
  19. c++原型模式(Prototype)
  20. HDU3853 概率DP

热门文章

  1. 【转】JAVA的静态变量、静态方法、静态类
  2. [转]Monkey测试简介
  3. FastDFS的简单使用
  4. php debug/phpstorm调试
  5. DeltaFish 选题报告总结
  6. 阿里云服务器安装ss使用
  7. postgresql update from
  8. PostgreSQL执行机制的初步学习
  9. [Windows Server 2012] MySQL移机方法
  10. pythno学习小结-替换python字典中的key值