裸的splay,只需要注意 max[-1]:=-maxlongint 就行了,否则在update的时候子节点的

max值会在max[-1]里选


/**************************************************************
    Problem: 1251
    User: BLADEVIL
    Language: Pascal
    Result: Accepted
    Time:16008 ms
    Memory:3448 kb
****************************************************************/
 
//By BLADEVIL
const
    sroot                   =-1;
var
    n, m                    :longint;
    i                       :longint;
    a, father               :array[-1..100010] of longint;
    k, l, r, v              :longint;
    root                    :longint;
    max, size, tree         :array[-1..100010] of longint;
    val                     :array[-1..100010] of longint;
    flag                    :array[-1..100010] of boolean;
    son                     :array[-1..100010,0..1] of longint;
     
procedure swap(var a,b:longint);
var
    c                       :longint;
begin
    c:=a; a:=b; b:=c;
end;
     
function get_max(a,b:longint):longint;
begin
    if a>b then exit(a) else exit(b);
end;
 
procedure renew_add(x,v:longint);
begin
    inc(tree[x],v); inc(val[x],v); inc(max[x],v);
end;
 
procedure renew_reverse(x:longint);
begin
    swap(son[x,1],son[x,0]);
    flag[x]:=not flag[x];
end;
     
procedure update(x:longint);
begin
    //if x=sroot then exit;
    max[x]:=get_max(tree[x],get_max(max[son[x,1]],max[son[x,0]]));
    size[x]:=size[son[x,1]]+size[son[x,0]]+1;
end;
     
function build(l,r:longint):longint;
var
    mid                     :longint;
begin
    mid:=(r+l) div 2;
    build:=mid;
    tree[mid]:=a[mid];
    if l+1<=mid then
    begin
        son[mid,0]:=build(l,mid-1);
        father[son[mid,0]]:=mid;
    end;
    if mid<=r-1 then
    begin
        son[mid,1]:=build(mid+1,r);
        father[son[mid,1]]:=mid;
    end;
    update(mid);
end;
 
procedure push_down(x:longint);
var
    l, r                    :longint;
begin
    l:=son[x,0]; r:=son[x,1];
    if flag[x] then
    begin
        if l<>-1 then renew_reverse(l);
        if r<>-1 then renew_reverse(r);
        flag[x]:=false;
    end;
    if val[x]<>0 then
    begin
        if l<>-1 then renew_add(l,val[x]);
        if r<>-1 then renew_add(r,val[x]);
        val[x]:=0;
    end;
end;
     
function find(x:longint):longint;
var
    t                       :longint;
begin
    t:=root;
    while true do
    begin
        push_down(t);
        if size[son[t,0]]+1=x then exit(t);
        if size[son[t,0]]+1>x then t:=son[t,0] else
        begin
            dec(x,size[son[t,0]]+1);
            t:=son[t,1];
        end;
    end;
end;
 
procedure rotate(x,y:longint);
var
    f                       :longint;
begin
    push_down(x);
    f:=father[x];
    father[son[x,y xor 1]]:=f;
    son[f,y]:=son[x,y xor 1];
    if f=root then root:=x else
        if f=son[father[f],0] then
            son[father[f],0]:=x else
            son[father[f],1]:=x;
    father[x]:=father[f];
    father[f]:=x;
    son[x,y xor 1]:=f;
    update(f);
    update(x);
end;
 
procedure splay(x,y:longint);
var
    u, v                    :longint;
begin
    while father[x]<>y do
    begin
        if father[father[x]]=y then
            rotate(x,ord(x=son[father[x],1])) else
        begin
            if son[father[x],0]=x then u:=1 else u:=-1;
            if son[father[father[x]],0]=father[x] then v:=1 else v:=-1;
            if u*v=1 then
            begin
                rotate(father[x],ord(x=son[father[x],1]));
                rotate(x,ord(x=son[father[x],1]));
            end else
            begin
                rotate(x,ord(x=son[father[x],1]));
                rotate(x,ord(x=son[father[x],1]));
            end;
        end;
    end;
    update(x);
end;
     
procedure add(l,r,v:longint);
var
    p                       :longint;
begin
    p:=find(l);splay(p,sroot);
    p:=find(r+2);splay(p,root);
    p:=son[son[root,1],0];
    renew_add(p,v);
end;
 
procedure reverse(l,r:longint);
var
    p                       :longint;
begin
    p:=find(l);splay(p,sroot);
    p:=find(r+2);splay(p,root);
    p:=son[son[root,1],0];
    renew_reverse(p);
end;
 
function ask_max(l,r:longint):longint;
var
    p                       :longint;
begin
    p:=find(l); splay(p,sroot);
    p:=find(r+2); splay(p,root);
    p:=son[son[root,1],0];
    ask_max:=max[p];
end;
     
begin
    fillchar(son,sizeof(son),255);
    read(n,m);
    max[-1]:=-maxlongint;
    for i:=1 to n do a[i]:=0;
    inc(n);
    root:=build(0,n);
    father[root]:=sroot;
    for i:=1 to m do
    begin
        read(k);
        if k=1 then
        begin
            read(l,r,v);
            add(l,r,v);
        end else
        begin
            read(l,r);
            if k=2 then    
                reverse(l,r) else
                writeln(ask_max(l,r));
        end;
    end;
end.

bzoj 1251 裸splay的更多相关文章

  1. bzoj 3223 裸splay

    裸的splay 今儿写的splay,由于自己刚开始学,发现几个容易漏掉的地方 1:开始给所有的儿子赋值为-1 2:给max[-1]赋值为-maxlongint 3:开始father[root]:=sr ...

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

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

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

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

  4. BZOJ 1251 Splay维护序列

    思路: splay维护序列的裸题 啊woc调了一天 感谢yzy大佬的模板-- //By SiriusRen #include <cstdio> #include <cstring&g ...

  5. 序列终结者 BZOJ 1251 Splay

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

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

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

  7. BZOJ 1251: 序列终结者

    1251: 序列终结者 Time Limit: 20 Sec  Memory Limit: 162 MB Submit: 3773  Solved: 1579 [Submit][Status][Dis ...

  8. bzoj 1251: 序列终结者 平衡树,fhqtreap

    链接 https://www.lydsy.com/JudgeOnline/problem.php?id=1251 思路 好简单的模板题 不过还是wrong了好几发 叶子节点要注意下,不能使用 遇到就不 ...

  9. bzoj 1588 平衡树 splay

    1588: [HNOI2002]营业额统计 Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 15446  Solved: 6076[Submit][Sta ...

随机推荐

  1. 《Cracking the Coding Interview》读书笔记

    <Cracking the Coding Interview>是适合硅谷技术面试的一本面试指南,因为题目分类清晰,风格比较靠谱,所以广受推崇. 以下是我的读书笔记,基本都是每章的课后习题解 ...

  2. 护网杯 three hit 复现(is_numeric引发的二次注入)

    1.题目源码 https://github.com/ZhangAiQiang/three-hit 题目并不真的是当时源码,是我根据做法自己写的,虽然代码烂,但是还好能达到复现的目的 ,兄弟们star一 ...

  3. 第二篇 Python初识别及变量名定义规范

    第一个Python程序 可以打开notepad或者其他文本编辑器,输入:print("Hello Python!"),将文件保存到任意盘符下,后缀名是  .py 两种python程 ...

  4. POJ 2229 递推

    Farmer John commanded his cows to search for different sets of numbers that sum to a given number. T ...

  5. NO11——01背包

    # include <stdio.h> # include <stdlib.h> # include <string.h> # define max(x,y) x& ...

  6. SSH 项目中 使用websocket 实现网页聊天功能

    参考文章  :java使用websocket,并且获取HttpSession,源码分析    http://www.cnblogs.com/zhuxiaojie/p/6238826.html 1.在项 ...

  7. lintcode-47-主元素 II

    47-主元素 II 给定一个整型数组,找到主元素,它在数组中的出现次数严格大于数组元素个数的三分之一. 注意事项 数组中只有唯一的主元素 样例 给出数组[1,2,1,2,1,3,3] 返回 1 挑战 ...

  8. WebStorm中配置ExtJS

    原文链接:http://zhidao.baidu.com/link?url=yX0wDWrL-b2P8k3JNNI38Fb6keuAgm0j9E-QBL1KfWXrZgLZ88grAOVJvat6dJ ...

  9. HDU 2139 Calculate the formula

    http://acm.hdu.edu.cn/showproblem.php?pid=2139 Problem Description You just need to calculate the su ...

  10. SpringBoot2.0

    建立可执行的Jars和Wars bootJar用于构建可执行的Jar: bootWar用于构建可执行的war. application.properties 不启动web服务器 spring.main ...