Here is the problem link: CSES - Distinct Colors

Here is the usaco link to the solution: soln.

I just copy pasted the same solution and submitted, which gave a TLE on the last case.

Here is my submission: cses submission. Here is the verdict (see this if visible: link):

I don’t quite understand why this method works (should give AC) and how to calculate the time complexity for it.

Also, I do not understand what are the datastructures that are defined in the solution, and why wasn’t a normal unordered_set used? I tried to use that and got a TLE for the second last test case instead of the last (last one got AC!).

Can anyone explain how to use those pbds data structures? I only know the basic ordered_set for order statistics. what are the other ones?

*Edit*: the problem was with the hash. using neal’s custom hash solves it! Here is the AC solution: https://cses.fi/paste/d67707c48bbca93b2b85e1/