关于线段树的写法
  • 板块学术版
  • 楼主LYqwq
  • 当前回复7
  • 已保存回复7
  • 发布时间2023/10/27 18:54
  • 上次更新2023/11/2 11:12:41
查看原帖
关于线段树的写法
399116
LYqwq楼主2023/10/27 18:54

rt,萌新求助

线段树的 update 与 query 中,应不应该传当前节点表示的区间 [l,r]?

就是以下两种写法,哪种更好?(本人较偏向第一种)

// rt:节点编号    l,r:修改区间     x:修改值
void update(int rt,int l,int r,int x){
	...
}
// query 同理
        struct node{
            int val,tag; // 节点的值与懒标记
            int l,r; // 节点表示的区间
        }t[N<<2];
// rt:节点编号   L,R:节点表示的区间    l,r:修改区间     x:修改值
void update(int rt,int L,int R,int l,int r,int x){
	...
}
// query 同理
        struct node{
            int val,tag; // 节点的值与懒标记
            // 这里不存节点表示的区间
        }t[N<<2];

QwQ 大佬勿喷谢谢

2023/10/27 18:54
加载中...