Hi! I am in search for problems that can be solved using the following technique: if we need to merge two sets in dfs, we put elements of the larger one into the smaller one, and in total asymptotics is $$$O(nlogn)$$$. If anyone knows of this kind of problems, i would be very grateful if you post some in the comments.
Auto comment: topic has been translated by Dannypa (original revision, translated revision, compare)
You can see the "dsu"-taged problems.
Thanks for narrowing the search space down to a couple hundreds
If your "set" means
std::set
or any self balancing tree, the total time complexity is $$$\mathcal{O}(n\log^2n)$$$, not $$$\mathcal{O}(n\log n)$$$.Why the downvotes smh
The technique is called "small to large" you will find some problems here
I thnk OP also meant small to large but just to be clear, the complexity is actually $$$\mathcal{O}(nlog^2n)$$$
There are many ways to store a set. One of them is
std::unordered_set
, which has $$$O(1)$$$ insertion and $$$O(size)$$$ traversal, which yields $$$O(n\log n)$$$ total time for some problems. So, the "small to large" idea is not tied to a certain complexity.Also, sometimes we are allowed to store duplicates (or we can prove that there are no duplicates). Then, we can store sets in linked lists and merge two of them in just $$$O(1)$$$. This wouldn't require "small to large" then, but I've seen at least one problem in this comment section, which can be solved this way.
Thanks!
Great! This list is helpful.
Can you share more lists of other topics? would be more helpful :)
link
credits: Abdelrhman_Akram
https://usaco.guide/plat/merging?lang=cpp
https://codeforces.net/contest/1620/problem/E This one