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

左偏树删除任意结点[内容有误] #5510

Closed
1 task
JiZiQian opened this issue Apr 15, 2024 · 1 comment
Closed
1 task

左偏树删除任意结点[内容有误] #5510

JiZiQian opened this issue Apr 15, 2024 · 1 comment
Labels
Content Bug / 页面内容有误 Something isn't working help wanted / 需要帮助 Extra attention is needed

Comments

@JiZiQian
Copy link
Contributor

请选择:

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

我正在访问这个页面

https://oi-wiki.org/ds/leftist-tree/#%E5%88%A0%E9%99%A4%E4%BB%BB%E6%84%8F%E8%8A%82%E7%82%B9

我发现页面有这样的问题

实现是否应改为:
???+ note "实现"
```cpp
int& rs(int x) { return t[x].ch[t[t[x].ch[1]].d < t[t[x].ch[0]].d]; }

// 有了 pushup,直接 merge 左右儿子就实现了删除节点并保持左偏性质
int merge(int x, int y) {
  if (!x || !y) return x | y;
  if (t[x].val < t[y].val) swap(x, y);
  t[rs(x) = merge(rs(x), y)].fa = x;
  t[x].d = t[rs(x)].d + 1;
  return x;
}

void pushup(int x) {
  if (!x) return;
  if (t[x].d != t[rs(x)].d + 1) {
    t[x].d = t[rs(x)].d + 1;
    pushup(t[x].fa);
  }
}

void erase(int x) {
  if (!x) return;
  x = merge(t[x].ch[0], t[x].ch[1]);
  pushup(x);
}
```

否则时间复杂度是O(log^2n)的

@JiZiQian JiZiQian added Content Bug / 页面内容有误 Something isn't working help wanted / 需要帮助 Extra attention is needed labels Apr 15, 2024
Copy link

welcome bot commented Apr 15, 2024

感谢你对 OI Wiki 的关注!记得在 Issue 中表达清楚自己的意思哦~

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

No branches or pull requests

1 participant