bzoj3196 Tyvj 1730 二逼平衡樹

2021-08-05 22:10:05 字數 2132 閱讀 7254

傳送門

終於把這個大坑填完了。。。

sb樹套樹

看似最不合理的方案恰恰是正確方案,樹套樹並不會mle,它的空間複雜度非常科學,o(nlogn)。(結果因為空間算錯陣列開小神奇的t掉,浪費了我兩天時間)

嘛。貌似除了操作二沒什麼好說的。轉換成判定性問題就好了,二分o(nlog

3 n)解決。其他按照正常線段樹和平衡樹寫就好了。

code:

#include#includeusing namespace std;

const

int n=50005;

struct node

inline void update()

inline void setch(int wh,node *child);

}pool[2000005],*null,*t[n<<2];

inline void node::setch(int wh,node *child)

int a[n];

int n,m,opt,x,y,z,tot;

inline node *getnew(int value)

inline void rotate(node *&now)

inline void splay(node *now,node *tar,node *&root)

inline void insert(int value,node *&root)

if(last==null)

now=getnew(value);

if(last->num>value) last->setch(0,now);

else last->setch(1,now);

splay(now,null,root);

}inline node *find(int value,node *&root)

if(now->num>value) now=now->ch[0];

else

now=now->ch[1];

}}inline void del(int value,node *&root)

if(now->ch[0]==null&&now->ch[1]==null)

if(now->ch[0]==null)

if(now->ch[1]==null)

node *pre=now->ch[0];

while(pre->ch[1]!=null) pre=pre->ch[1];

splay(pre,now,root);

pre->setch(1,now->ch[1]);

pre->fa=null;

root=pre;

}inline int rank(int value,node *&root)

if(now->num>value) now=now->ch[0];

else ranking+=now->ch[0]->size+now->sum,now=now->ch[1];

}return ranking;

}inline void change(int value,int num,node *&root)

inline int pre(int value,node *&root)

inline int nxt(int value,node *&root)

inline void init(int l,int r,node *&root)

void build(int l,int r,int

now)

int askrank(int l,int r,int l,int r,int

now,int num)

inline int askkth(int l,int r,int num)

return l-1;

}void changenum(int p,int l,int r,int

now,int num)

int askpre(int l,int r,int l,int r,int

now,int num)

int asknxt(int l,int r,int l,int r,int

now,int num)

int main()

return 0;

}

BZOJ3196 Tyvj 1730 二逼平衡樹

description 您需要寫一種資料結構 可參考題目標題 來維護乙個有序數列,其中需要提供以下操作 1.查詢k在區間內的排名 2.查詢區間內排名為k的值 3.修改某一位值上的數值 4.查詢k在區間內的前驅 前驅定義為小於x,且最大的數 5.查詢k在區間內的後繼 後繼定義為大於x,且最小的數 in...

bzoj3196 Tyvj 1730 二逼平衡樹

description 您需要寫一種資料結構 可參考題目標題 來維護乙個有序數列,其中需要提供以下操作 1.查詢k在區間內的排名 2.查詢區間內排名為k的值 3.修改某一位值上的數值 4.查詢k在區間內的前驅 前驅定義為小於x,且最大的數 5.查詢k在區間內的後繼 後繼定義為大於x,且最小的數 in...

BZOJ 3196 TYVJ 1730 二逼平衡樹

k 在區間內的排名 2.查詢區間內排名為 k的值 3.修改某一位值上的數值 4.查詢 k 在區間內的前驅 前驅定義為小於 x,且最大的數 5.查詢 k 在區間內的後繼 後繼定義為大於 x,且最小的數 第一行兩個數n,m 表示長度為 n 的有序序列和 m個操作 第二行有 n 個數,表示有序序列 下面有...