$f$ be a function on real line carrying compact sets to compact sets and fiber of every point under $f$ is closed , is $f$ continuous ? Let $f:\mathbb R \to \mathbb R$ be a function such that it carries compact sets to compact sets and $f^{-1}(\{x\})$ is closed for every  $x \in \mathbb R$ , then is $f$ continuous ?

(I know that if $f$ is a function on real line having ivt and preimage of every singleton is closed then $f$ is continuous ; also if a function on real line has ivt and carries compact sets to compact sets then $f$ is continuous ; this question is motivated from theses two facts )
Suppose $f$ is not continuous from the right at $x_0$ and $f(x_0)=y_0$. Notice that for all $x&gt;x_0$, $f([x_0,x])$ is compact. Then there exists a sequence $\{x_n\}_{n\in\mathbb{N}}$ and $y_1\neq y_0$ such that $x_n&gt;x_0$, $\lim_{n\to+\infty}x_n=x_0$ and $\lim_{n\to+\infty}f(x_n)=y_1$. Furthermore, $y_1\in f([x_0,x])$ for all $x$ because of the compactness. Also $f^{-1}(\{y_1\})$ is closed, and $f(x_0)=y_0\neq y_1$. So $x_0$ lies in an open set $(a,b)$ such that $y_1\notin f((a,b))$. It's a contradiction.
Hint: By the Heine-Borel theorem, every compact subset of $\mathbb R$ is closed and bounded. Therefore, f carries closed sets into closed sets.

Claim: A function f from X into Y is continuous if and only if preimages of closed sets in Y are closed in X.

If you can prove this,this will show the answer is yes.