跳到正文

个人记录

复杂线段树模板

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

文章信息

发布
2023年2月22日
收录
2025年12月12日
更新
2026年11月14日
篇幅
约 2 分钟

版本

  1. v1当前
C++
namespace SegmentTree {
	#define ls pos << 1
	#define rs pos << 1 | 1
	
	struct Node {} tr[N << 2];
	const Node empty = (Node){/**/};
	int add[N]; //懒标记,较多的时候开strct
	Node operator + (Node x, Node y)
	{
		if (x == empty) return y;
		if (y == empty) return x;
		/**/;
	}
	void pushup(int pos) {tr[pos] = tr[ls] + tr[rs];}
	void build(int l, int r, int pos)
	{
		tr[pos] = empty;
		if (l == r)
		{
			/**/;
			return;
		}
		int mid = (l + r) >> 1;
		build(l, mid, ls), build(mid + 1, r, rs);
		pushup(pos);
	}
	void lazy(int pos)
	{
		/**/;
	}
	void pushdown(int pos)
	{
		/**/;
	}
	void update(int l, int r, int pos, int L, int R)
	{
		if (L <= l && r <= R) return lazy(pos);
		pushdown(pos);
		int mid = (l + r) >> 1;
		if (L <= mid) update(l, mid, ls, L, R);
		if (mid < R) update(mid + 1, r, rs, L, R);
		pushup(pos);
	}
	Node query(int l, int r, int pos, int L, int R)
	{
		if (l == r) return tr[pos];
		pushdown(pos);
		int mid = (l + r) >> 1; Node ans = empty;
		if (L <= mid) ans = ans + query(l, mid, ls, L, R);
		if (mid < R) ans = ans + query(mid + 1, r, rs, L, R);
		return ans;
	}
	
	#undef ls
	#undef rs
}; using namespace SegmentTree;
原文