-
Notifications
You must be signed in to change notification settings - Fork 512
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
Create spoj-cot.mdx (solution for the problem I added about persisten… #5073
base: master
Are you sure you want to change the base?
Conversation
…t segment tree) The code solution for the problem count on tree from spoj on persistent segment tree concept
for more information, see https://pre-commit.ci
Hi, I just submitted this pull request. Please let me know if there’s anything I need to adjust or address. Thanks! |
Could you please help me resolve the problem "Some checks were not successful"? Is the " '''cpp " causing the problem? |
fyi, you can test ur mdx code at usaco.guide/editor |
hmm, it's giving this error:
|
I changed the solution metadata kind to internal after committing this change. I think I accidentally included it in a different pull request |
yeah thats what it looks like, just change the solution type to internal |
…data of the problem called count on tree)
I think I solved it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just some misc style changes + other
for examples of how the code should roughly look, u can look at other internal solutions (here's a good example)
Co-authored-by: Justin Ji <[email protected]>
Thank you for the suggestions! Is there anything else that you would suggest modifying? |
for more information, see https://pre-commit.ci
…code) Modified the explanation part and organized the code
I changed the code and the explanation part |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Corrected explanation, specifically the "handling overcounting with LCA" part
Changed the variable name from a to u and b to v
Modified the note, so it is more grammatically correct
corrected typo
Is there anything else that you suggest I modify? @SansPapyrus683 |
solutions/advanced/spoj-cot.mdx
Outdated
We subtract the frequencies of nodes from the root node to the LCA and its parent because we count the nodes twice from the root node to the LCA. In addition, since the LCA is on the path of u to v, we subtract the frequencies from the LCA and the parent of the LCA to consider the value of the LCA. | ||
|
||
$$ | ||
\texttt leftCountFromUToV = leftCount[u]+leftCount[v]−leftCount[LCA]−leftCount[parentOfLCA] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uh this isn't what i meant by texttt lmao
i meant like wrap all the variable names with texttt (including lca)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also do I wrap the variable u and v too?
**Note:** | ||
Value compression is used to effectively handle large numbers, which could otherwise cause problems with indexing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrap in an tag or something, you can find examples by ctrl-f ing the reop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I use Spoiler tag and give it a title note
or can I use $ \ textb f { } $
@SansPapyrus683
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fyi, value compression isn't strictly needed (altho it makes it faster, ig)
my code is here (u can remove fast io, altho using std::endl
times out cuz its slow)
Deleted long longs and the build function since they weren't necessary
for more information, see https://pre-commit.ci
compr.push_back(val[i]); | ||
} | ||
|
||
sort(compr.begin(), compr.end()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im curious, is there a specific reason ur code coordinate compresses? ig it is faster, but it isn't needed for this problem
as a side note, you definitely do not need 7e6 nodes. 5e6 sufficed for me, and my range was from 0 to INT_MAX
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right. To avoid segmentation fault I set the number of nodes to 7e6. I changed the number of nodes to 5e6.
I used coordinate compression because the segment tree is a frequency tree and the constraint of the values isn't given in the problem statement. I used this method to ensure that there won't be a problem when building the segment tree. It also speeds up the program
I wrote the coed without the compression and it exceeded the time limit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idk my code was perfectly fine without coord compression lol, but ig its fine the way it is
(also, i think maybe even 2e6 or 3e6 would work because ur coord compressing)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, 2e6 works
I decreased the number of nodes since 5e6 would suffice
Reduced the number of nodes to 2e6
Is there anything else that you suggest I modify? |
…t segment tree)
The code solution for the problem count on tree from spoj on persistent segment tree concept
Place an "x" in the corresponding checkbox if it is done or does not apply to this pull request.