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

[内容有误] 左偏树页面中「棘手的操作」代码在 C++17 及以上有误 #5607

Closed
1 task
Tiphereth-A opened this issue May 16, 2024 · 3 comments · Fixed by #5609
Closed
1 task
Assignees
Labels
Content Bug / 页面内容有误 Something isn't working help wanted / 需要帮助 Extra attention is needed

Comments

@Tiphereth-A
Copy link
Member

请选择:

  • 我正在着手修复这个问题

我正在访问这个页面

https://oi-wiki.org/ds/leftist-tree/#scoi2011%E6%A3%98%E6%89%8B%E7%9A%84%E6%93%8D%E4%BD%9C

我发现页面有这样的问题

开 O2 的前提下,C++14 可以通过,但是 C++17C++20 不可以。

@Tiphereth-A Tiphereth-A added Content Bug / 页面内容有误 Something isn't working help wanted / 需要帮助 Extra attention is needed labels May 16, 2024
@HeRaNO HeRaNO self-assigned this May 17, 2024
@HeRaNO
Copy link
Collaborator

HeRaNO commented May 17, 2024

我在 Linux 上测试的结果是 C++14 没有问题,但是 C++17 和 C++20 在 pushdown 函数处爆栈了。

@HeRaNO
Copy link
Collaborator

HeRaNO commented May 17, 2024

这个页面的很多写法也没对齐。在核心操作:合并一节中的代码和任意节点删除的代码,还有后面例题代码中的合并就不一样。

这个写法最早的版本就有了。左偏树无需交换左右儿子的写法感觉是有问题的,我把它替换到左偏树模板题,C++ 17 无法通过,但 C++14 可以。C++17 C++14

rs(x) 引用保留后可以通过模版题。C++17 renew

merge(rs(x), y)rs(x) 一定先于 merge 调用,此时 merge 返回正确结果,但是 ch[rs(x)].d 可能被修改,如果 rs(x) = merge 晚于 merge 调用,就可能和先于的那次结果不同,因此要保留引用。
See: 求值顺序 - cppreference 19)

@HeRaNO
Copy link
Collaborator

HeRaNO commented May 17, 2024

改为保留引用,C++14, C++17C++20 均能通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content Bug / 页面内容有误 Something isn't working help wanted / 需要帮助 Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants