This is a problem from the S.-T YAU COLLEGE MATH CONTEST in 2012. The original problem is
Let $f(x)$ be a real measurable function defined on $[a,b]$. Let $n(y)$ be the number of solutions of the equation $f(x) = y$. Prove that $n(y)$ is a measurable function on $\mathbb{R}$.
Later it was proven that the condition $f$ is measurable is not strong enough, and counterexamples could be easily constructed using the Cantor-Lebesgue function. However, I still find it difficult to tackle if $f$ is assumed continuous, in which condition this proposition holds.
By the continuity of $f$ we know that the set of roots of $f(x)=y$ for any given $y$ should be closed, but I don't know how to get around from this to the measurability of $n(y)$. Any help will be appreciated.