【问题标题】:(end-start+1)*Lazy[treeIndex]?(end-start+1)*懒惰[treeIndex]?
【发布时间】:2021-12-19 21:02:26
【问题描述】:

请帮助我理解分段树延迟传播中的这句话。

我本来希望只增加 Lazy[treeIndex]:

tree[treeIndex] += Lazy[treeIndex]

上下文:

void RangeUpdate(int node, int st, int end, int l, int r, long long val)
{
if(Lazy[node] != 0)  // if node is lazy then update it
{
    tree[node] += (end-st+1)*Lazy[node];

在这里找到的完整代码——

https://gist.githubusercontent.com/Princeraaz/0bcc10f8347c26a035fc7c6bb6ed27f9/raw/4c91093a518ebeed955daf1c3588d8a9bf2edf82/Lazy_RangeUpdate.cpp

来源:https://medium.com/nybles/understanding-range-queries-and-updates-segment-tree-lazy-propagation-and-mos-algorithm-d2cd2f6586d8

【问题讨论】:

    标签: algorithm segment-tree


    【解决方案1】:

    也许它意味着对其后代叶子的更新总和——其范围内的最后一个叶子减去第一个叶子,再加上 1 以包括第一个叶子。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-13
      • 2022-01-09
      • 2012-06-02
      • 2015-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多