From c66a7ee3327dc2cb64ce7bf2a89909109f2151af Mon Sep 17 00:00:00 2001 From: small_bear <2421342308@qq.com> Date: Wed, 27 Nov 2024 00:14:21 +0800 Subject: [PATCH] Update index.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit segment tree2 ’modify‘ bugfix --- moonbit-docs/docs/examples/segment-tree2/index.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/moonbit-docs/docs/examples/segment-tree2/index.md b/moonbit-docs/docs/examples/segment-tree2/index.md index 5ea9fa6c..253a9dc4 100644 --- a/moonbit-docs/docs/examples/segment-tree2/index.md +++ b/moonbit-docs/docs/examples/segment-tree2/index.md @@ -150,13 +150,17 @@ fn modify( modify_r: Int, tag: LazyTag ) -> Node { - if modify_l > r || l > modify_r { + if l > r { + empty_node + } else if modify_l > r || l > modify_r { self } else if modify_l <= l && modify_r >= r { self.apply(tag) } else { - guard let Node(~left, ~right, ..) = self - left.apply(tag) + right.apply(tag) + guard let Node(left~, right~, ..) = self + let mid = (l + r) >> 1 + left.modify(l, mid, modify_l, modify_r, tag) + + right.modify(mid+1, r, modify_l, modify_r, tag) } } ```