Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Template of SegmentTree may be wrong? #55

Closed
ZjuYTW opened this issue Aug 27, 2022 · 1 comment
Closed

The Template of SegmentTree may be wrong? #55

ZjuYTW opened this issue Aug 27, 2022 · 1 comment

Comments

@ZjuYTW
Copy link

ZjuYTW commented Aug 27, 2022

https://github.com/wisdompeak/LeetCode/blob/master/Template/SegmentTree/range_sum.cpp#L33
In the PushDown method of RangeSum temlpate, the code just simply copy the parent's info to childrens', which is wrong.

I test it by the following code

int main(){
    SegTreeNode* root = new SegTreeNode(0, 10, 0);
  
    root->updateRange(5, 10, 20);

    assert(root->queryRange(6,6) == 20); // where the template gives us 40
}

We could fix this by introducing lazy_val as the member variable.

@wisdompeak
Copy link
Owner

谢谢提醒。简单修正了一下,欢迎测试。

@ZjuYTW ZjuYTW closed this as completed Aug 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants