java 板子dddd

Posted goto_1600

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 板子dddd相关的知识,希望对你有一定的参考价值。


 class Splay

    class node
    
        int v,father;
        int ch[]=new int[2];
        int sum;
        int recy;
    ;
    Splay()
    
        for(int i=0;i<e.length;i++)
        
            e[i]=new node();

        
    
    node[] e=new node[100010];
    int n,points;//
    void update(int x)
    
        e[x].sum=e[e[x].ch[0]].sum+e[e[x].ch[1]].sum+e[x].recy;
    
    int identify(int x)
    
        return e[e[x].father].ch[0]==x?0:1;
    
    void connect(int x,int f,int son)
    
        e[x].father=f;
        e[f].ch[son]=x;
    
    void rotate(int x)
    
        int y=e[x].father;
        int mroot=e[y].father;
        int mrootson=identify(y);
        int yson=identify(x);
        int B=e[x].ch[yson^1];
        connect(B,y,yson);connect(y,x,(yson^1));connect(x,mroot,mrootson);
        update(y);update(x);
    
    void splay(int at,int to)
    
        to=e[to].father;
        while(e[at].father!=to)
        
            int up=e[at].father;
            if(e[up].father==to) rotate(at);
            else if(identify(up)==identify(at))
            
                rotate(up);
                rotate(at);
            
            else
            
                rotate(at);
                rotate(at);
            
        
    
    int crepoint(int v,int father)
    
        n++;
        e[n].v=v;
        e[n].father=father;
        e[n].sum=e[n].recy=1;
        e[n].ch[0]=e[n].ch[1]=0;
        return n;
    
    void destroy(int x)
    
        e[x].v=e[x].ch[0]=e[x].ch[1]=e[x].sum=e[x].father=e[x].recy=0;
        if(x==n) n--;
    
    void init()
    
        points=n=e[0].ch[1]=0;
        e[e[0].ch[1]].v=e[e[0].ch[1]].father=e[e[0].ch[1]].sum=e[e[0].ch[1]].recy=e[e[0].ch[1]].ch[0]=e[e[0].ch[1]].ch[1]=0;
    
    int getroot()return e[0].ch[1];
    int find(int v)
    
        int now=e[0].ch[1];
        while(true)
        
            if(e[now].v==v)
            
                splay(now,e[0].ch[1]);
                return now;
            
            int next=v<e[now].v?0:1;
            if(e[now].ch[next]==0) return 0;
            now=e[now].ch[next];
        
    
    int build(int v)
    
        points++;
        if(points==1)
        
            e[0].ch[1]=n+1;
            crepoint(v,0);
        
        else
        
            int now=e[0].ch[1];
        
        return 0;
    
    void push(int v)
    
        int add=build(v);
        splay(add,e[0].ch[1]);
    
    void pop(int v)//
    
        int deal=find(v);
        if(deal==0) return;
        points--;
        if(e[deal].recy>1)
        
            e[deal].recy--;
            e[deal].sum--;
            return;
        
        if(e[deal].ch[0]==0)
        
            e[0].ch[1]=e[deal].ch[1];
            e[e[0].ch[1]].father=0;
        
        else
        
            int lef=e[deal].ch[0];
            while(e[lef].ch[1]!=0) lef=e[lef].ch[1];
            splay(lef,e[deal].ch[0]);
            int rig=e[deal].ch[1];
            connect(rig,lef,1);connect(lef,0,1);
            update(lef);
        
        destroy(deal);
    
    int rank(int v)
    
        int ans=0,now=e[0].ch[1];
        while(true)
        
            if(e[now].v==v)
            
                ans+=e[e[now].ch[0]].sum;
                splay(now,e[0].ch[1]);
                return ans+1;
            
            if(now==0) return 0;
            if(v<e[now].v) now=e[now].ch[0];
            else
            
                ans=ans+e[e[now].ch[0]].sum+e[now].recy;
                now=e[now].ch[1];
            
        
    
    int atrank(int x)
    
        if(x>points) return -1000000;
        int now=1000000;
        while(true)
        
            int minused=e[now].sum-e[e[now].ch[1]].sum;
            if(x>e[e[now].ch[0]].sum&&x<=minused) break;
            if(x<minused) now=e[now].ch[0];
            else
            
                x=x-minused;
                now=e[now].ch[1];
            
        
        splay(now,e[0].ch[1]);
        return e[now].v;
    
    int upper(int v)
    
        int now=e[0].ch[1];
        int result=100000;
        while(now>0)
        
            if(e[now].v>=v&&e[now].v<result) result=e[now].v;
            if(v<e[now].v) now=e[now].ch[0];
            else now=e[now].ch[1];
        
        return result;
    
    int lower(int v)
    
        int now=e[0].ch[1];
        int result=-1000;
        while(e[0].ch[1]>0)
        
            if(e[now].v<=v&&e[now].v>result) result=e[now].v;
            if(v>e[now].v) now=e[now].ch[1];
            else now=e[now].ch[0];
        
        return result;
    
;
public class Main
    public static void main(String args[])
    
        Splay tt=new Splay();
        tt.build(100000);
        System.out.println("qwq");
    

以上是关于java 板子dddd的主要内容,如果未能解决你的问题,请参考以下文章

java 板子dddd

java 实现绘制直线图,<init>(DDDD)V

不换行

DDDD:事件数据

java代码在片段活动中不起作用

java 代码片段【JAVA】