# Intermediate value property and continuity

We say that a function $f:\mathbb{R}\to\mathbb{R}$ has the intermediate value property (ivp) if for $a<b$ in $\mathbb{R}$ we have $$f([a,b]) \supseteq [\min\{f(a),f(b)\}, \max\{f(a), f(b)\}].$$ The intermediate value theorem states that continous functions have the ivp. Is there a non-continuous function $f:\mathbb{R}\to\mathbb{R}$ with the ivp and the property that $f^{-1}(\{c\})$ is closed for all $c\in\mathbb{R}$?

Say, local bounded variation is enough: if $f$ is discontinuous at a point $a$, there exist two numbers $A<B$ such that $f$ takes the values less than $A$ and more than $B$ in any (punctured) neighborhood of $a$. Clearly variation of $f$ in any such neighborhood is infinite.
Of course if the preimage of any point $f^{-1}(c)$ is closed, we also may conclude that $f$ is continuous: take $c$ between $A$ and $B$ but $c\ne f(a)$, then $f^{-1}(c)$ does not contain $a$, but contains points arbitrarily close to $a$, hence $f^{-1}(c)$ is not closed.