BZOJ3224 普通平衡樹 SPlay

2021-07-25 04:11:15 字數 1079 閱讀 4211

誒乙個中午種了兩棵樹

寫平衡樹之前一定要明確陣列的定義,想好每個過程怎麼寫之後再開始動手寫

想清楚每個操作返回的是結點的編號還是結點的值

誒又是wall編譯救了我

#include #include #define inf 1<<30

#define n 200050

using namespace std;

int tr[n],siz[n],fa[n],s[n][2];

int cur[n],cnt,rt;

inline void update(int t)

void rot(int x,int &k)

s[y][l] = s[x][r]; s[x][r] = y;

fa[x] = z; fa[y] = x; fa[ s[y][l] ] = y;

update(y); update(x);

}void splay(int x,int &k)

rot(x,k); }}

int qf(int x,int t)

else return qf(x,s[t][0]);

}int qa(int x,int t)

else return qa(x,s[t][1]);

}int query(int x,int t)

int kth(int k,int t)

void ins(int x,int &t,int f)

if (x == tr[t])

if (x < tr[t]) ins(x,s[t][0],t); else ins(x,s[t][1],t);

update(t);

}void del(int x,int &t) else

update(u); update(v);

}inline void koo(int t)

int main()

case 2:

case 3:

case 4:

case 5:

case 6:

} }return 0;

}

bzoj3224普通平衡樹

您需要寫一種資料結構 可參考題目標題 來維護一些數,其中需要提供以下操作 1.插入x數 2.刪除x數 若有多個相同的數,因只刪除乙個 3.查詢x數的排名 若有多個相同的數,因輸出最小的排名 4.查詢排名為x的數 5.求x的前驅 前驅定義為小於x,且最大的數 6.求x的後繼 後繼定義為大於x,且最小的...

BZOJ3224 普通平衡樹

題目傳送門 您需要寫一種資料結構 可參考題目標題 來維護一些數,其中需要提供以下操作 1.插入x數 2.刪除x數 若有多個相同的數,因只刪除乙個 3.查詢x數的排名 若有多個相同的數,因輸出最小的排名 4.查詢排名為x的數 5.求x的前驅 前驅定義為小於x,且最大的數 6.求x的後繼 後繼定義為大於...

BZOJ3224 普通平衡樹

您需要寫一種資料結構 可參考題目標題 來維護一些數,其中需要提供以下操作 1.插入x數 2.刪除x數 若有多個相同的數,因只刪除乙個 3.查詢x數的排名 若有多個相同的數,因輸出最小的排名 4.查詢排名為x的數 5.求x的前驅 前驅定義為小於x,且最大的數 6.求x的後繼 後繼定義為大於x,且最小的...