Continuous function with compact set Let $f$ be a continuous function from the reals $\mathbb{R}$ onto $I=[0,1]$ with usual topology. Prove that if $C$ is a subset of $I$ and the preimage of $C$ is closed in $\mathbb{R}$ then $C$ is closed in $I$.
My attempt is to use normal space properties but it does not help. 
 A: Hint: There is a compact interval $J=[c,d]$ such that $f(J)=I$. If $(x_n)\subseteq C$ converges in $I$, take preimages and use compactness of $J$ to show that $\lim x_n\in C$.
A: Hint: it will be easier (in my opinion) to show that $C^c$ must be open in I, take a point in $x \in C^c$, and look for $r>0$ s.t $B(x,r) \subset C^c$. 
A: Let $D$ be the complementary space of $C$. We are going to show that $D$ is open. Suppose that $D$ is not open. There exists $y\in D$ such that for every  open interval $y\in J$, $J\cap[0,1]\cap C$ is not empty. Since $f$ is continuous, $f^{-1}(J\cap [0,1])$ is open. Let $x\in f^{-1}(J\cap [0,1])$ such that $f(x)=y$, there exists an interval $I_x$,  $x\in I_x\subset f^{-1}(J\cap [0,1])$, we choose $I_x=(a,b)$ maximal. 
If $a$ and $b$ are not real numbers, $I_x=R$ $D=[0,1]$ and $C$ is the empty subset contradiction, since the empty subset is closed.
Suppose that $a$ and $b$ are real numbers. $f((a,b))$ is an interval contained in $D$. $a$ and $b$ are contained in $f^{-1}(C)$. This implies that $f(a)$ and $f(b)$ cannot be in the interior of $f((a,b))$ since it is contained in $D$. We deduce that $f([a,b])]=[f(a),f(b)]$ or $[f(b),f(a)]$. $y$ cannot be in the interior of $f((a,b))]$, since $y$ is an accumulation point of $C$. This implies that $y=f(a)$ or $y=f(b)$ contrariction.
Suppose that $I_x=(a,+\infty)$, $f(I_x)$ is an interva $[c,d]$ where $0<c<d<1$, the intermediate value theorem implies that $f((-\infty,a))=[0,1]$, again there exists $x'\in (-\infty,a)$ such that $f(x')$. $I_{x'}$ the maximal open interval contained in $f^{-1}(D)$ and containing $x'$ is of the form $(-\infty,b)$. We deduce that $f^{-1}(C)\subset [b,a]$ and is compact since it is closed. This implies that $C$ is closed. Contradiction. We deduce that $f(I_x)$ contains $0$ or $1$. Suppose that $0\in f(I_x)$, since $y$ is an accumulation point of $C$, $f(I_x)=[0,y]$, $f(a)=0$ since $f(a)\in C, f(a)\neq y $ and if $f(a)$ in the interior of $[0,y]$ the intermediate value theorem implies there exists $x'\in I_x$ such that $f(x')=f(a)$. Since $f$ is surjective, $f((-\infty, a))=[0,1]$ (use the intermediate value theorem). There exists $x_1$ in $(-\infty, a)$ such that $f(x_1)=y$. Again we apply the previous step to show that the maximal open interval in $f^{-1}(D)$ containing $x_1$ is of the form $(-\infty,b)$. This implies that $f^{-1}(C)$ is contained in $[b,a]$, since it is a closed subset we deduce that $f^{-1}(C)$ is compact. This implies that $C$ is compact since the image of a compact subset by a continuous map is compact and henceforth closed. Contradiction. The case where $1\in f(I_x)$ is similar.
The case where $I_x=(-\infty,a)$ is similar.
