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

Create spoj-cot.mdx (solution for the problem I added about persisten… #5073

Open
wants to merge 38 commits into
base: master
Choose a base branch
from

Conversation

1Nigar357
Copy link
Contributor

@1Nigar357 1Nigar357 commented Jan 22, 2025

…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.

  • I have tested my code.
  • I have added my solution according to the steps here.
  • I have followed the code conventions mentioned here.
    • I understand that if it is clear that I have not attempted to follow these conventions, my PR will be closed.
    • If changes are requested, I will re-request a review after addressing them.
  • I have linked this PR to any issues that it closes.

…t segment tree)

The code solution for the problem count on tree from spoj on persistent segment tree concept
@1Nigar357 1Nigar357 requested a review from dongliuu as a code owner January 22, 2025 22:36
@1Nigar357
Copy link
Contributor Author

Hi, I just submitted this pull request. Please let me know if there’s anything I need to adjust or address. Thanks!

@1Nigar357
Copy link
Contributor Author

1Nigar357 commented Jan 22, 2025

Could you please help me resolve the problem "Some checks were not successful"? Is the " '''cpp " causing the problem?

@TheGamingMousse
Copy link
Contributor

fyi, you can test ur mdx code at usaco.guide/editor

@TheGamingMousse
Copy link
Contributor

hmm, it's giving this error:

Internal solution spoj-cot isn't linked to all of its problems (see above). Did you forget to update the solution metadata of a module after adding an internal solution?

  Error:Internal solution spoj-cot isn't linked to all of its problems (see abo  ve). Did you forget to update the solution metadata of a module after adding a  n internal solution?
  
  - gatsby-node.js:1 
    /home/runner/work/usaco-guide/usaco-guide/.cache/compiled/gatsby-node.js:1:8    567
  
  - Array.forEach
  
  - gatsby-node.js:1 Object.n.createPages
    /home/runner/work/usaco-guide/usaco-guide/.cache/compiled/gatsby-node.js:1:7    973
  
  - task_queues:95 processTicksAndRejections
    node:internal/process/task_queues:95:5
  
  - api-runner-node.js:[48](https://github.com/cpinitiative/usaco-guide/actions/runs/12919237231/job/36029331675?pr=5073#step:7:49)7 runAPI
    [usaco-guide]/[gatsby]/src/utils/api-runner-node.js:487:16
  

not finished Running gatsby-plugin-sharp.IMAGE_PROCESSING jobs - 13.133s
failed createPages - 0.814s

@1Nigar357
Copy link
Contributor Author

1Nigar357 commented Jan 23, 2025

I changed the solution metadata kind to internal after committing this change. I think I accidentally included it in a different pull request

@TheGamingMousse
Copy link
Contributor

TheGamingMousse commented Jan 23, 2025

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

@1Nigar357
Copy link
Contributor Author

I think I solved it

Copy link
Contributor

@TheGamingMousse TheGamingMousse left a 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)

solutions/advanced/spoj-cot.mdx Outdated Show resolved Hide resolved
solutions/advanced/spoj-cot.mdx Show resolved Hide resolved
solutions/advanced/spoj-cot.mdx Outdated Show resolved Hide resolved
solutions/advanced/spoj-cot.mdx Outdated Show resolved Hide resolved
solutions/advanced/spoj-cot.mdx Outdated Show resolved Hide resolved
solutions/advanced/spoj-cot.mdx Outdated Show resolved Hide resolved
@1Nigar357
Copy link
Contributor Author

Thank you for the suggestions! Is there anything else that you would suggest modifying?

solutions/advanced/spoj-cot.mdx Outdated Show resolved Hide resolved
solutions/advanced/spoj-cot.mdx Outdated Show resolved Hide resolved
solutions/advanced/spoj-cot.mdx Show resolved Hide resolved
solutions/advanced/spoj-cot.mdx Outdated Show resolved Hide resolved
solutions/advanced/spoj-cot.mdx Outdated Show resolved Hide resolved
solutions/advanced/spoj-cot.mdx Outdated Show resolved Hide resolved
solutions/advanced/spoj-cot.mdx Outdated Show resolved Hide resolved
solutions/advanced/spoj-cot.mdx Outdated Show resolved Hide resolved
solutions/advanced/spoj-cot.mdx Show resolved Hide resolved
…code)

Modified the explanation part and organized the code
@1Nigar357
Copy link
Contributor Author

I changed the code and the explanation part

solutions/advanced/spoj-cot.mdx Outdated Show resolved Hide resolved
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
@1Nigar357
Copy link
Contributor Author

Is there anything else that you suggest I modify? @SansPapyrus683

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]
Copy link
Contributor

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)

Copy link
Contributor Author

@1Nigar357 1Nigar357 Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it

Copy link
Contributor Author

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?

Comment on lines +28 to +29
**Note:**
Value compression is used to effectively handle large numbers, which could otherwise cause problems with indexing.
Copy link
Contributor

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

Copy link
Contributor Author

@1Nigar357 1Nigar357 Jan 29, 2025

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

Copy link
Contributor

@TheGamingMousse TheGamingMousse left a 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)

solutions/advanced/spoj-cot.mdx Outdated Show resolved Hide resolved
solutions/advanced/spoj-cot.mdx Outdated Show resolved Hide resolved
solutions/advanced/spoj-cot.mdx Outdated Show resolved Hide resolved
solutions/advanced/spoj-cot.mdx Outdated Show resolved Hide resolved
solutions/advanced/spoj-cot.mdx Outdated Show resolved Hide resolved
Deleted long longs and the build function since they weren't necessary
compr.push_back(val[i]);
}

sort(compr.begin(), compr.end());
Copy link
Contributor

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

Copy link
Contributor Author

@1Nigar357 1Nigar357 Feb 1, 2025

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.

Copy link
Contributor

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)

Copy link
Contributor Author

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
@1Nigar357
Copy link
Contributor Author

Is there anything else that you suggest I modify?

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.

5 participants