Suppose that $f\colon\Bbb R\to\Bbb R$ takes intermediate values, i.e. if $f(a) < x < f(b)$ for some $a,b$ then $x = f(t)$ for some $t$ between $a$ and $b$. Suppose also that the set of all $x$ such that $f(x) = r$ is closed for all $r \in\Bbb Q$. Prove that $f$ is continuous.
So I understand the Intermediate Value theorem, and generally know how to show that a function is continuous, but could I have a hint to help me get started on this question?