Hi codeforces!
I recently wrote sqrt-decomposition + dsu, and I only had to use snm if the query contains the whole block. What would be the asymptotics of this solution?
It may seem obvious to you that the asymptotics will be $$$O(n \cdot \sqrt{n \cdot \varphi^{-1} {(n)}})$$$ ($$$\varphi^{-1} {(n)}$$$ — the inverse Ackerman function).
But in fact the asymptotics is — $$$O(n \cdot B \cdot \varphi^{-1}{(n)} + \frac{n ^ 2}{B})$$$ ($$$B$$$ — block size) and in order to achieve the asymptotics with an accreman under the sqrt we need to know $$$\varphi^{-1}{(n)}$$$ to put $$$B = \sqrt{n * \varphi^{-1}{-1} {(n)}}$$$, and to do that we need to know $$$\varphi^{-1} {(n)}$$$. So it comes down to a quick calculation of $$$\varphi^{-1} {(n)}$$$. Is it possible to do this?
Is it theoretical or practical question?
For practical reasons, this should not bother you. For all reasonable values of $$$n \le 10^{18}$$$, $$$\alpha(n) \le 4$$$ (could be easily calculated, using the recurrence from wikipedia). You can put $$$B = \sqrt{n}$$$, or, if you want to achieve the optimal time, then you need to benchmark the code to get know, which parts of it are more fast and which are more slow to adjust the constant $$$B$$$ properly. It will be somewhere near $$$\sqrt{n}$$$, but could easily be $$$5$$$ times less than it, or $$$5$$$ times greater — all depends on the constant factors.
For theoretical reasons, it is easy to calculate the inverse Ackerman function say in $$$\mathcal{O}(n)$$$. You just need to follow the recurrence, and stop the calculations, once the values are too big. The following is a sketch of the solution, though you need to be careful with big integers and overflowing.
The Ackerman function grows so fast that it should be not so hard to prove that the code above produces correct answer, though it doesn't calculates all of the required values.