跳到正文

个人记录

[Fun]压行版FhqTreap

LJ07约 2 分钟
原文
文章信息与版本

文章信息

发布
2022年3月30日
收录
2025年12月12日
更新
2026年11月12日
篇幅
约 2 分钟

版本

  1. v1当前

丑的一批

C++
struct Fhq {
	struct node {int ls, rs, val, sum, rnk;}nd[N + 5];int rt, cnt, x, y, z, t, ans;
	void ud(int c) {nd[c].sum = nd[nd[c].ls].sum + nd[nd[c].rs].sum + 1;}
	int nw(int d) {return nd[++cnt] = (node) {0, 0, d, 1, rand() << 15 | 114514}, cnt;}
	int mg(int L, int R) {return (!L || !R) ? L + R : ((nd[L].rnk < nd[R].rnk) ? (nd[L].rs = mg(nd[L].rs, R), ud(L), L) : (nd[R].ls = mg(L, nd[R].ls), ud(R), R));}
	void sp(int &L, int &R, int c, int d) {	(!c) ? (L = R = 0) : ((nd[c].val <= d) ? (L = c, sp(nd[L].rs, R, nd[L].rs, d), 0) : (R = c, sp(L, nd[R].ls, nd[R].ls, d), 0), ud(c), 0);}
	void ins(int d) {sp(x, y, rt, d), rt = mg(mg(x, nw(d)), y);}
	void del(int d) {sp(x, y, rt, d), sp(x, z, x, d - 1), rt = mg(x, y);}
	int kth(int c, int d) {return d < (t = nd[nd[c].ls].sum + 1) ? kth(nd[c].ls, d) : (d == t ? c : kth(nd[c].rs, d - t));}
	int pre(int d) {return sp(x, y, rt, d - 1),	ans = nd[kth(x, nd[x].sum)].val, rt = mg(x, y), ans;}
	int nxt(int d) {return sp(x, y, rt, d),	ans = nd[kth(y, 1)].val, rt = mg(x, y), ans;}
	Fhq() : cnt(0), rt(0) {}
}fhq;

Just for fun

原文
存档评论2 条抓取于