Skip to content

Instantly share code, notes, and snippets.

@lomnom
Last active October 22, 2025 00:55
Show Gist options
  • Select an option

  • Save lomnom/157c4d837ec15c1cdd2f5896c2e4ad56 to your computer and use it in GitHub Desktop.

Select an option

Save lomnom/157c4d837ec15c1cdd2f5896c2e4ad56 to your computer and use it in GitHub Desktop.
Hints for NYRCS pset 11: PURQ segtree

Hints

Segment tree

Hint #1 This questions wants you to implement a conventional segment tree. You can use the nyrcs template
Hint #2 It wants you to find the minimum instead of the sum. How do you do that?
Hint #3 Refer to the slides, the answer is mostly already in the segment tree code section.

Mountains

Fun one ngl

Hint #1: A hint You can use a sum segment tree creatively to count the number of items in a range
Hint #1a: Answer to hint 1 You can use a segment tree to count the number of things in a range. If there is a thing at position #i, set index #i to 1. If there is no thing, set index #i to 0. Then, range sum in [L, R] to count the number of things within [L, R].
Hint #2 Starting from an empty segment tree, is there an order to insert the mountains?
Hint #2h: Further hint We want to insert in an order order which guarantees that all other mountains in the segreee right after insertion are lower than the inserted item.
Hint #2a: Answer to hint 2 Insert from lowest to highest.
Hint #3: Why am i WA? Have you remembered to consider what to do if there are multiple mountains of the same height?
Hint #3a: Answer to not WA Insert one of them, evaluate, then remove it. Repeat with all mountains of the same height. Then after evaluating all, you insert all back in.

Collectmushrooms2

Do you really understand segment tree?

Hint #1 This question needs you to modify the segtree a little. Go understand it’s implementation first then try.
Hint #2 You need to modify the segtree such that each segment is not only responsible for storing the max. They now store two pieces of data.
Hint #2a: Answer The segments now need to store both the maximum within their range, and the index of the maximum.
Hint #3a: Answer to implement Change comb to take in pair. What else should change.
Hint #3aa Implementation :) figure it out.

Crypto

💀 Literal math.

Hint #1 This question is literal math.
Hint #2 Its math where something somewhere can use a segment tree.
Hint #3 The segment tree is used similar to in mountains

No more hints :) its a challenge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment