博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HNOI 2002 营业额统计(Splay入门)
阅读量:6975 次
发布时间:2019-06-27

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

第一次写splay。。

首先你必须要明确一些事情 -> 坚信splay不难, 好吧, 下面推荐一篇, 作为入门, 之后再做一下这道题(其实并不需要splay), 就可以开始splay之路了

这道题没什么好解释, 裸题, 中文的, 不需要解释了

参考了cxlove的博客

code->

#include 
using namespace std;#define N 100005#define oo 1<<30#define rep(i, s, t) for(int i = s; i <= t; ++i)int n, tot, root, key[N];struct Splay{ int fa[N], ch[N][2]; void newnode(int &r, int father, int w) { r = ++tot; fa[r] = father; key[r] = w; ch[r][0] = 0; ch[r][1] = 0; } void rotate(int x, int kind) { int y = fa[x]; ch[y][!kind] = ch[x][kind]; fa[ch[y][!kind]] = y; if(fa[y]) ch[fa[y]][ch[fa[y]][1]==y] = x; fa[x] = fa[y]; fa[y] = x; ch[x][kind] = y; } void splay(int u) { while(fa[u]) { if(!fa[fa[u]]) rotate(u, ch[fa[u]][0] == u); else { int v = fa[u]; int kind = ch[fa[v]][0]==v; if(ch[v][kind] == u) rotate(u, !kind), rotate(u, kind); else rotate(v, kind), rotate(u, kind); } } root = u; } int insert(int k) { int u = root; if(key[root] ^ k) { while(ch[u][key[u]

转载于:https://www.cnblogs.com/pbvrvnq/p/8530169.html

你可能感兴趣的文章
云计算解码:技术架构和产业运营
查看>>
提高代码质量 CheckStyle FindBugs PMD
查看>>
shell技巧之以逆序形式打印行
查看>>
Java面试题集(六)
查看>>
读枯燥的技术书时怎么集中精神?
查看>>
iOS 依据文本内容为TextView动态定义高度
查看>>
CCF系列之ISBN号码(201312-2)
查看>>
SQL Server 内存使用量下降问题
查看>>
问题MySQL server has gone away
查看>>
iOS的Cookie存取看我绝对够!!
查看>>
azkaban 安装
查看>>
GIX4中懒加载
查看>>
tomcat排错过程
查看>>
virus.win32.parite.h病毒查杀
查看>>
【初級篇】华为NAT技术(静态NAT)
查看>>
Android telephony MMS 学习笔记
查看>>
LVM动态扩容、缩减
查看>>
winform 窗体关闭事件
查看>>
socket编程
查看>>
MySQL 表空间管理
查看>>