我正在学习段树(以范围最小查询为例)并且在理解查询段树的算法部分背后的原因时遇到了一些问题。
我理解构建段树的部分没有问题,我不明白为什么在这个函数中:
int RMQUtil(int *st, int ss, int se, int qs, int qe, int index)
{
// If segment of this node is a part of given range, then return the min of the segment
if (qs <= ss && qe >= se)
return st[index]; // this is the part I am struggling with
// If segment of this node is outside the given range
if (se < qs || ss > qe)
return INT_MAX;
// If a part of this segment overlaps with the given range
int mid = getMid(ss, se);
return minVal(RMQUtil(st, ss, mid, qs, qe, 2*index+1), RMQUtil(st, mid+1, se, qs, qe, 2*index+2));
}
如果该节点的段是给定范围的一部分,则返回该段的最小值。