# Continuity of function with intermediate values

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?

-
Assume that $f$ is not continuous at $x$. Find a sequence $(x_n)$ that is monotone, has limit $x$, and is such that $|f(x_n)-f(x)|>\delta$ for some $\delta>0$ and all $n$. Using this sequence, find a rational number $r\ne f(x)$ and a sequence $(y_n)$ with limit $x$ such that $f(y_n)=r$ for each $n$. This will contradict the closedness condition. –  David Mitra Apr 5 '13 at 1:31