• 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;
    }
    有不懂欢迎咨询 QQ:1326487164(添加时记得备注)
  • 相关阅读:
    c_水程序
    Arlenmbx!!!!
    java
    c语言随机函数&&时间函数
    2016省赛总结
    666
    【UOJ#389】【UNR#3】白鸽(欧拉回路,费用流)
    【洛谷P3756】[CQOI2017]老C的方块(最小割)
    CF704D Captain America(上下界网络流)
    AtCoder Regular Contest 097
  • 原文地址:https://www.cnblogs.com/bluefly-hrbust/p/11440643.html
Copyright © 2020-2023  润新知