博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
bzoj 3223 裸splay
阅读量:6951 次
发布时间:2019-06-27

本文共 3866 字,大约阅读时间需要 12 分钟。

裸的splay

今儿写的splay,由于自己刚开始学,发现几个容易漏掉的地方

1:开始给所有的儿子赋值为-1

2:给max[-1]赋值为-maxlongint

3:开始father[root]:=sroot

4:在find和rotate中的push_down

5:数组的下边界为-1

6:push_down中要给标签清空

7:build中要给tree数组赋值

8:rotate操作不熟悉

由于不熟悉,发现的问题有很多,以后多加练习就好了

/**************************************************************    Problem: 3223    User: BLADEVIL    Language: Pascal    Result: Accepted    Time:4720 ms    Memory:2668 kb****************************************************************/ //By BLADEVILconst    sroot                           =-1;     var    n, m                            :longint;    x, y                            :longint;    a                               :array[-1..100010] of longint;    tree, size, father              :array[-1..100010] of longint;    son                             :array[-1..100010,0..1] of longint;    flag                            :array[-1..100010] of boolean;    root                            :longint;    i                               :longint;     procedure swap(var a,b:longint);var    c                               :longint;begin    c:=a; a:=b; b:=c;end;     procedure update(x:longint);begin    size[x]:=size[son[x,1]]+size[son[x,0]]+1;end;     procedure renew_reverse(x:longint);begin    swap(son[x,1],son[x,0]);    flag[x]:=not flag[x];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;end;     function build(l,r:longint):longint;var    mid                             :longint;begin    mid:=(l+r) div 2;    build:=mid;    tree[mid]:=a[mid];    if mid-1>=l then    begin        son[mid,0]:=build(l,mid-1);        father[son[mid,0]]:=mid;    end;    if mid+1<=r then    begin        son[mid,1]:=build(mid+1,r);        father[son[mid,1]]:=mid;    end;    update(mid);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];    son[f,y]:=son[x,y xor 1];    father[son[x,y xor 1]]:=f;    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 x=son[father[x],0] then u:=1 else u:=-1;            if father[x]=son[father[father[x]],0] 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 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;     begin    fillchar(son,sizeof(son),255);    read(n,m);    for i:=1 to n do a[i]:=i;    inc(n);    root:=build(0,n);    father[root]:=sroot;    for i:=1 to m do    begin        read(x,y);        reverse(x,y);    end;    for i:=2 to n do write(find(i),' '); writeln;end.   

 

转载于:https://www.cnblogs.com/BLADEVIL/p/3458619.html

你可能感兴趣的文章
逆向路由器固件之敏感信息泄露 Part2
查看>>
WebSocket与消息推送
查看>>
apache做转发
查看>>
一条SQL的改写
查看>>
常用的慢查询日志分析工具
查看>>
MySQL单表模拟锁的几个场景
查看>>
因子分解机模型简介
查看>>
SAP LSMW 物料主数据导入毛重净重放大1000倍问题之对策
查看>>
外嫁美的被指违约 东芝创维合作或重谈
查看>>
HCI的全面升温可能导致软件定义型传统阵列遭遇搁浅
查看>>
特斯拉和SolarCity下月召开特别股东大会 表决合并事宜
查看>>
Denyhosts shell script
查看>>
高清摄像机镜头的质量和价格分析
查看>>
中国移动计划牵头推动5G传输国际标准立项
查看>>
苹果补上了可被未授权收集传感器数据的iPhone漏洞
查看>>
《UNIXLinux程序设计教程》一2.6 文件结束和错误指示器
查看>>
Q3全球太阳能企业融资规模达30亿美元 环增76%
查看>>
华为4.5G助力TDC创造丹麦移动网络峰值速率新纪录
查看>>
融合系统的前景如何?
查看>>
科达教育行业解决方案发布会在广州举行
查看>>