Skip to content

Use __lg to make treeJump shorter#260

Open
IvanRenison wants to merge 2 commits into
kth-competitive-programming:mainfrom
IvanRenison:treeJump_use__lg
Open

Use __lg to make treeJump shorter#260
IvanRenison wants to merge 2 commits into
kth-competitive-programming:mainfrom
IvanRenison:treeJump_use__lg

Conversation

@IvanRenison

Copy link
Copy Markdown
Contributor

It breaks the case when P is empty, but thats not an useful case

It breaks the case when P is empty, but thats not an useful case
@simonlindholm

Copy link
Copy Markdown
Member

I don't care about the case of empty P, because that's not a tree, but I do care about sz(P) == 1. __lg(0) is undefined, right?

@IvanRenison

IvanRenison commented May 12, 2024

Copy link
Copy Markdown
Contributor Author

Oh, yes, I saw in this stack overflow answer that it's -1, and in my machine gives -1, but according to this codeforces blog you are right.
I fixed it with sz(P) < 2 ? 0 :1 + __lg(sz(P) - 1)

@lrvideckis

Copy link
Copy Markdown
Contributor

if sz(P)==1 then __lg(1)=0 and is not UB, so original code would have worked

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

Successfully merging this pull request may close these issues.

3 participants