不懂就问
查看原帖
不懂就问
226113
火羽白日生楼主2020/8/8 15:44

为什么这样就会RE

node *find_rank(int x){
    node *now=root;
    while(1){
        if(now->lson){
            if(x<=now->lson->size)
                now=now->lson;
            else if(x==now->lson->size+1)
                break;
            else{
                now=now->rson;
                x-=(now->lson->size+1);
            }
        }
        else{
            if(x==1)
                break;
            else{
                now=now->rson;
                x--;
            }
        }
    }
    splay(now,root);
    root=now;
    return now;
}

然后变成

node *find_rank(int x){
    node *now=root;
    while(1){
        if(now->lson){
            int t=now->lson->size;
            if(x<=t)
                now=now->lson;
            else if(x==t+1)
                break;
            else{
                now=now->rson;
                x-=(t+1);
            }
        }
        else{
            if(x==1)
                break;
            else{
                now=now->rson;
                x--;
            }
        }
    }
    splay(now,root);
    root=now;
    return now;
}

他就AC了 (大雾

2020/8/8 15:44
加载中...