Open
Conversation
Contributor
|
I have added a few details to fill the missing points in the description, do have a look.
|
Contributor
|
Please change the branch the pr is being merged to !!!! |
sg60692
reviewed
Sep 5, 2023
|
|
||
| node nodes[N]; | ||
|
|
||
| void g(int u) { |
Contributor
There was a problem hiding this comment.
Suggestion: pull would be a better name
| } | ||
| } | ||
|
|
||
| int find(int root, int l) { |
Contributor
There was a problem hiding this comment.
It would be better if Splay are added into the template first and using that this question is solved as it is highly unlikely to write splay from scratch in live contests
Contributor
There was a problem hiding this comment.
Incase you feel we should merge this solution right now and may be add to the template later, would also work
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Let a deck of cards$D$ be represented as an array of pair of integers $(v_a, v_b)$ where $v_a$ is the number printed on the up face and $v_b$ is the number printed on the down face.
Let the first deck be$D_1$ and the seconde deck be $D_2$ .
Observation: The face up cards of the first deck always form the following sequence -
Our data-structure must support the following operations -$T$ denote transformation on elements
Let
These operations can be made by using a
splay tree.It is chosen as:
The first update can be made using lazy update based in the following transformation.
$$T(D_2, l, r, 1) = [ T(D_2, mid + 1, r, 1) T(D_2, l, mid, 1) ]$$
$$T(T(D_2, l, r, 1), 1) = T(D_2, l, r, 0) = D_2$$
The second and third query can be made using the following fact.
$$F_A(l, r) = F_A(l, mid) + F_A(mid + 1, r)$$
$$F_B(l, r) = F_B(l, mid) + F_B(mid + 1, r)$$
This follows that
Which helps us compute values of$F$ in constant time without actually performing the transformations
The actual transformations will just reverse the left and right pointer of child and call transformations on them