LCT模版

本文深入探讨了LCT数据结构的基本原理,包括其插入、删除、查找等操作,并通过实例解析了如何在HDU 5002问题中运用LCT来优化解题思路。LCT作为一种强大的树形结构,适用于解决动态维护树的平衡性和查询问题,对于提升算法效率有着显著作用。
摘要由CSDN通过智能技术生成

相关资料点击打开链接

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <vector>
using namespace std;
template <class T>
inline bool rd(T &ret) {
	char c; int sgn;
	if (c = getchar(), c == EOF) return 0;
	while (c != '-' && (c<'0' || c>'9')) c = getchar();
	sgn = (c == '-') ? -1 : 1;
	ret = (c == '-') ? 0 : (c - '0');
	while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');
	ret *= sgn;
	return 1;
}
template <class T>
inline void pt(T x) {
	if (x <0) {
		putchar('-');
		x = -x;
	}
	if (x>9) pt(x / 10);
	putchar(x % 10 + '0');
}
typedef long long ll;
typedef pair<int, int> pii;
const int N = 30005;
const int inf = 10000000;
struct Node *null;
struct Node {
	Node *fa, *ch[2];
	int size;
	int val, ma, sum, id;
	bool rev;
	inline void put() {
	}
	inline void clear(int _val, int _id) {
		fa = ch[0] = ch[1] = null;
		size = 1;
		rev = 0;
		id = _id;
		val = ma = sum = _val;
	}
	inline void push_up() {
		size = 1 + ch[0]->size + ch[1]->size;
		sum = ma = val;
		if (ch[0] != null) {
			sum += ch[0]->sum;
			ma = max(ma, ch[0]->ma);
		}
		if (ch[1] != null) {
			sum += ch[1]->sum;
			ma = max(ma, ch[1]->ma);
		}
	}
	inline void push_down() {
		if (rev) {
			ch[0]->flip();
			ch[1]->flip();
			rev = 0;
		}
	}
	inline void setc(Node *p, int d) {
		ch[d] = p;
		p->fa = this;
	}
	inline bool d() {
		return fa->ch[1] == this;
	}
	inline bool isroot() {
		return fa == null || fa->ch[0] != this && fa->ch[1] != this;
	}
	inline void flip() {
		if (this == null)return;
		swap(ch[0], ch[1]);
		rev ^= 1;
	}
	inline void go() {//从链头开始更新到this
		if (!isroot())fa->go();
		push_down();
	}
	inline void rot() {
		Node *f = fa, *ff = fa->fa;
		int c = d(), cc &#
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值