$f: M \rightarrow \mathbb{R}$ is continuous if and only if for every $a \in \mathbb{R}$, $X\_a$ = {x $\in$ M | f(x) < a} and $Y\_a$ = {x $\in$ M | f(x) > a} are open sets. 

( $\implies$) If f is continuous, then $f^{-1}$(A) is open for every A $\subset \mathbb{R}$. Then, $X\_a$ = $f^{-1}((-\infty, a))$ is open. Similarly, $Y\_a$ is open.

Can anyone help me to prove that if $X\_a$ and $Y\_a$ are open for every a, then f is continuous?