线段树不处理输入数据的所有段。有没有有效的日期结构呢?

Segment tree doesn't take care of all segments of input data. Is there an efficient date structure that does?

线段树是一种高效但并不总是完全有用的数据结构。例如:如果我们有一个长度为 8 的数组,它将处理 1-2、3-4、5-6、7-8、1-4、5-8 和 1-8 段。但是很多会被遗漏,例如 2-3、2-4、4-5、6-7 等。是否有一种有效的数据结构可以处理输入数据的所有段?

不,这不是真的。它实际上 "take care" 每个间隔。

例如,在上面的线段树中,如果您需要执行范围[4, 7]的查询,它将转到左子树,如[0, 4] -> [3, 4] -> [ 4, 4] 和右子树 [5, 9] -> [5, 7] 然后聚合 [4, 4] 和 [5, 7] 的结果并将结果传递给根。

我建议用笔和纸进行模拟或使用调试器来查看递归调用的幕后情况。祝你好运!