2-3-4 tree留坑
Posted bluefly-hrbust
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2-3-4 tree留坑相关的知识,希望对你有一定的参考价值。
#include<bits/stdc++.h> #define LL long long #define pii pair<int,int> #define mp make_pair using namespace std; const int maxx = 2e5+6; const double alpha = 0.75; struct node int l,ml,mr,r; int val[4]; int size; int fa; tree[maxx]; int cnt=0; int root; int newnode(int w,int fa) tree[++cnt].size=1; tree[cnt].val[1]=w; tree[cnt].fa=fa; return cnt; int inserts(int rt,int w) int fa; if (tree[rt].size==3) if (rt==root) root=newnode(tree[rt].val[2],-1); rt=root; tree[root].l=newnode(tree[rt].val[1],root); tree[root].ml=newnode(tree[rt].val[3],root); tree[tree[root].l].l=tree[rt].l; tree[tree[root].l].ml=tree[rt].ml; tree[tree[root].ml].l=tree[rt].mr; tree[tree[root].ml].ml=tree[rt].r; else int fa=tree[rt].fa; if (tree[fa].size==1) if (tree[rt].val[2]<tree[fa].val[1]) tree[fa].mr=tree[fa].ml; tree[fa].ml=newnode(tree[rt].val[3],fa); tree[tree[fa].ml].l=tree[rt].mr; tree[tree[fa].ml].ml=tree[rt].r; tree[fa].l=newnode(tree[rt].val[1],fa); tree[tree[fa].l].l=tree[rt].l; tree[tree[fa].l].ml=tree[rt].ml; tree[fa].val[2]=tree[fa].val[1]; tree[fa].val[1]=tree[rt].val[2]; else tree[fa].val[2]=tree[rt].val[2]; tree[fa].ml=newnode(tree[rt].val[1],fa); tree[fa].mr=newnode(tree[rt].val[3],fa); tree[tree[fa].ml].l=tree[rt].l; tree[tree[fa].ml].ml=tree[rt].ml; tree[tree[fa].mr].l=tree[rt].mr; tree[tree[fa].mr].mr=tree[rt].r; else if (tree[fa].size==2) if (tree[rt].val[2]<tree[fa].val[1]) tree[fa].val[3]=tree[fa].val[2]; tree[fa].val[2]=tree[fa].val[1]; tree[fa].val[1]=tree[rt].val[2]; tree[fa].r=tree[fa].mr; tree[fa].mr=tree[fa].ml; tree[fa].ml=newnode(tree[rt].val[3],fa); tree[fa].l=newnode(tree[rt].val[1],fa); tree[tree[fa].ml].l=tree[rt].mr; tree[tree[fa].ml].ml=tree[rt].r; tree[tree[fa].l].l=tree[rt].l; tree[tree[fa].l].ml=tree[rt].ml; else if (tree[rt].val[2]<tree[fa].val[2]) tree[fa].val[3]=tree[fa].val[2]; tree[fa].val[2]=tree[rt].val[2]; tree[fa].r=tree[fa].mr; tree[fa].ml=newnode(tree[rt].val[1],fa); tree[fa].mr=newnode(tree[rt].val[3],fa); tree[tree[rt].ml].l=tree[rt].l; tree[tree[rt].ml].ml=tree[rt].ml; tree[tree[rt].mr].l=tree[rt].mr; tree[tree[rt].mr].mr=tree[rt].r; else tree[fa].val[3]=tree[rt].val[2]; tree[fa].mr=newnode(tree[rt].val[1],fa); tree[fa].r=newnode(tree[rt].val[3],fa); tree[tree[fa].mr].l=tree[rt].l; tree[tree[fa].mr].ml=tree[rt].ml; tree[tree[fa].r].l=tree[rt].ml; tree[tree[fa].r].ml=tree[rt].mr; rt=fa; if (w<tree[rt].val[1]) int main() scanf("%d") return 0;
以上是关于2-3-4 tree留坑的主要内容,如果未能解决你的问题,请参考以下文章