bzoj 3223 裸splay
裸的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:
User: BLADEVIL
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/
//By BLADEVIL
const
sroot =-;
var
n, m :longint;
x, y :longint;
a :array[-..] of longint;
tree, size, father :array[-..] of longint;
son :array[-..,..] of longint;
flag :array[-..] 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,]]+size[son[x,]]+;
end;
procedure renew_reverse(x:longint);
begin
swap(son[x,],son[x,]);
flag[x]:=not flag[x];
end;
procedure push_down(x:longint);
var
l, r :longint;
begin
l:=son[x,]; r:=son[x,];
if flag[x] then
begin
if l<>- then renew_reverse(l);
if r<>- then renew_reverse(r);
flag[x]:=false;
end;
end;
function build(l,r:longint):longint;
var
mid :longint;
begin
mid:=(l+r) div ;
build:=mid;
tree[mid]:=a[mid];
if mid->=l then
begin
son[mid,]:=build(l,mid-);
father[son[mid,]]:=mid;
end;
if mid+<=r then
begin
son[mid,]:=build(mid+,r);
father[son[mid,]]:=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,]]+=x then exit(t);
if size[son[t,]]+>x then t:=son[t,] else
begin
dec(x,size[son[t,]]+);
t:=son[t,];
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 ];
father[son[x,y xor ]]:=f;
if f=root then root:=x else
if f=son[father[f],] then
son[father[f],]:=x else
son[father[f],]:=x;
father[x]:=father[f];
father[f]:=x;
son[x,y xor ]:=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],])) else
begin
if x=son[father[x],] then u:= else u:=-;
if father[x]=son[father[father[x]],] then v:= else v:=-;
if u*v= then
begin
rotate(father[x],ord(x=son[father[x],]));
rotate(x,ord(x=son[father[x],]));
end else
begin
rotate(x,ord(x=son[father[x],]));
rotate(x,ord(x=son[father[x],]));
end;
end;
end;
update(x);
end;
procedure reverse(l,r:longint);
var
p :longint;
begin
p:=find(l); splay(p,sroot);
p:=find(r+); splay(p,root);
p:=son[son[root,],];
renew_reverse(p);
end;
begin
fillchar(son,sizeof(son),);
read(n,m);
for i:= to n do a[i]:=i;
inc(n);
root:=build(,n);
father[root]:=sroot;
for i:= to m do
begin
read(x,y);
reverse(x,y);
end;
for i:= to n do write(find(i),' '); writeln;
end.
bzoj 3223 裸splay的更多相关文章
- bzoj 1251 裸splay
裸的splay,只需要注意 max[-1]:=-maxlongint 就行了,否则在update的时候子节点的 max值会在max[-1]里选 /*************************** ...
- 【splay】文艺平衡树 BZOJ 3223
Description 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:翻转一个区间,例如原有序序列是5 4 3 2 1,翻转区间是[2,4]的话,结果是5 2 3 ...
- [BZOJ 3223 & Tyvj 1729]文艺平衡树 & [CodeVS 3243]区间翻转
题目不说了,就是区间翻转 传送门:BZOJ 3223 和 CodeVS 3243 第一道题中是1~n的区间翻转,而第二道题对于每个1~n还有一个附加值 实际上两道题的思路是一样的,第二题把值对应到位置 ...
- BZOJ 3223 Tyvj 1729 文艺平衡树(Splay)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3223 [题目大意] 给出一数列,问m次区间翻转后的结果. [题解] Splay 区间翻 ...
- bzoj 3223 文艺平衡树 - Splay
3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3884 Solved: 2235[Submit][Sta ...
- BZOJ 3223: Tyvj 1729 文艺平衡树(splay)
速度居然进前十了...第八... splay, 区间翻转,用一个类似线段树的lazy标记表示是否翻转 ------------------------------------------------- ...
- bzoj 3223: Tyvj 1729 文艺平衡树 (splay)
链接: https://www.lydsy.com/JudgeOnline/problem.php?id=3223 题面: 3223: Tyvj 1729 文艺平衡树 Time Limit: 10 S ...
- BZOJ 3223: Tyvj 1729 文艺平衡树-Splay树(区间翻转)模板题
3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 6881 Solved: 4213[Submit][Sta ...
- BZOJ 3223 Splay区间翻转
思路: 区间翻转的裸题 终于tm理解splay了-- //By SiriusRen #include <cstdio> #include <cstring> #include ...
随机推荐
- 多图片上传(base64方式传至后台)
<!DOCTYPE html><html><head> <meta http-equiv="X-UA-Compatible" conten ...
- python程序设计——基本语言特性
参考<Python程序设计(第2版)> 清华大学出版社 董付国 ##### 除特殊说明外,以下代码示例,均为python 3.6版本 ##### 一.Python语言特性 1.python ...
- 安装arch系统时,把ubuntu的efi分区格式化
导致无法从grub进入ubuntu,之后我进入win10,把ubuntu的分区都删了. 再重启,只能进入黑色的grub界面,显示 grub>> 甚至无法进入win10.只能通过在开机时按F ...
- PyQt5图像全屏显示
Windows装这个:https://pypi.python.org/pypi/PyQt5Ubuntu输入这个:sudo apt-get install python3-pyqt5 或者直接输入:pi ...
- linux 命令小结(随时更新)
代码备份命令: tar cvf 备份文件名 要备份的目录名 查看Linux服务器内存使用情况: 1.free命令 free -m [root@localhost ~]# free -m ...
- Chromium之文件类型
.grp: Generate your project. 是由Json(JavaScript Object Notation)(or Python?)来解析,根据环境(OS,Compiler..)来生 ...
- 玩adb和fastboot
http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece7631046893b4c4380143fd3d1027fa3c215cc790a1b18 ...
- 【题解】APIO2013机器人
其实这题前前后后的思考时间加起来应该有两天之久了,dp状态,转移方式等等都还是比较好想,然而左看右看觉得spfa复杂度未免太爆炸……然后选择看了一篇题解,发现在多重优化之下,其实是可以过的…… 首先建 ...
- [Leetcode] n queens ii n皇后问题
Follow up for N-Queens problem. Now, instead outputting board configurations, return the total numbe ...
- Eclipse中的引用项目报Could not find *.apk!解决办法
百度上很多关于Could not find *.apk!这种编译报错的解决帖子,但是笔主在这里主要说一下在 引用工程项目的场景 下报这个错误消息的问题(不影响本项目的正常编译运行!). 笔主刚从谷歌上 ...