Treap 템플릿(단순)
                                            
 8103 단어  Treap
                    
#includecontinue;
        }
        if(s>t[now].s)
        {
            now=t[now].rc;
            continue;
        }
    }
    return 0;
}
ll maxn()//    
{
    ll now=root;
    while(1)
    {
        if(t[now].rc==0)
        return now;
        now=t[now].rc;
    }
}
ll minn()//    
{
    ll now=root;
    while(1)
    {
        if(t[now].lc==0)
        return now;
        now=t[now].lc;
    }
}
void zig(ll x)//   
{
    if(root==t[x].fa)
    root=x;
    ll ff=t[t[x].fa].fa;
    t[t[x].fa].fa=x;
    if(ff!=0)
    {
        if(t[ff].lc==t[x].fa)
        t[ff].lc=x;
        if(t[ff].rc==t[x].fa)
        t[ff].rc=x;
    }
    if(t[x].lc!=0)
    t[t[x].lc].fa=t[x].fa;
    t[t[x].fa].rc=t[x].lc;
    t[x].lc=t[x].fa;
    t[x].fa=ff;
    return;
}
void zag(ll x)//   
{
    if(root==t[x].fa)
    root=x;
    ll ff=t[t[x].fa].fa;
    t[t[x].fa].fa=x;
    if(ff!=0)
    {
        if(t[ff].lc==t[x].fa)
        t[ff].lc=x;
        if(t[ff].rc==t[x].fa)
        t[ff].rc=x;
    }
    if(t[x].rc!=0)
    t[t[x].rc].fa=t[x].fa;
    t[t[x].fa].lc=t[x].rc;
    t[x].rc=t[x].fa;
    t[x].fa=ff;
    return;
}
void strike_off(ll x)//   
{
    while(t[x].lc!=0||t[x].rc!=0)
    {
        if(t[x].lc!=0&&t[x].rc==0)
        {zag(t[x].lc);continue;}
        if(t[x].rc!=0&&t[x].lc==0)
        {zig(t[x].rc);continue;}
        if(t[x].lc!=0&&t[x].rc!=0)
        {
            if(t[t[x].lc].sumelse
            zig(t[x].rc);
        }
    }
    if(t[x].fa!=0)
    {
        if(t[t[x].fa].lc==x)
        t[t[x].fa].lc=0;
        if(t[t[x].fa].rc==x)
        t[t[x].fa].rc=0;
    }
    --size;
    return;
}
void insert(ll s)//   
{
    ++size;
    t[++w].s=s;
    t[w].sum=rand()%1000050;
    if(size==1)
    {
        root=w;
        return;
    }
    ll pre=root;
    ll now=root;
    while(now!=0)
    {
        if(s==t[now].s)
        cout<<"shenmegui???"<if(scontinue;
        }
        if(s>t[now].s)
        {
            pre=now;
            now=t[now].rc;
            continue;
        }
    }
    if(sif(s>t[pre].s)
    t[pre].rc=w;
    t[w].fa=pre;
    while(t[w].sumif(t[t[w].fa].lc==w)
        {
            zag(w);
            continue;
        }
        if(t[t[w].fa].rc==w)
        {
            zig(w);
            continue;
        }
    }
    return;
}
int main()
{
    srand(19981017);
    return 0;
}      이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
SPOJ3273——ORDERSET - Order statistic set(Treap)K-TH(S) : return the k-th smallest element of S COUNT(S,x): return the number of elements of S smaller than x Input Line...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.