Let $f:M\to\mathbb{R}$. If the sets $\{x:f(x)>a\}$ and $\{x:f(x)<a\}$ are open subsets of $M$ for every rational $a$, show that $f$ is continuous.
My attempt:
I want to prove that $\{x:f(x)>b\}$ and $\{x:f(x)<b\}$ are open subsets of $M$ for every real $b$. Then the problem becomes much simpler.
Let $A=\{x|x>b, x\in\mathbb{Q}\}$ and $B=\{x|x<b, x\in\mathbb{Q}\}$. $A$ and $B$ are countable.
I claim that $\displaystyle\{x:f(x)>b\}=\bigcup_{x_i\in A}\{x:f(x)>x_i\}$
To prove this, let $y\in\{x:f(x)>b\}$.
Then $f(y)>b$.
Let $x_j$ be a rational satisfying $b<x_j<f(y)$. $x_j>b\text{ and }x_j\in\mathbb{Q}\implies x_j\in A$
$\displaystyle f(y)>x_j\implies y\in\{x:f(x)>x_j\}\implies y\in\bigcup_{x_i\in A}\{x:f(x)>x_i\}$
Thus, $\displaystyle\{x:f(x)>b\}\subset\bigcup_{x_i\in A}\{x:f(x)>x_i\}$ ----------------- (1)
Let $\displaystyle y\in\bigcup_{x_i\in A}\{x:f(x)>x_i\}$
$\implies y\in\{x:f(x)>x_j\}$ for some $x_j\in A$.
$\implies f(y)>x_j$ and $x_j\in A\implies x_j>b\implies f(y)>b\implies y\in\{x:f(x)>b\}$
Thus, $\displaystyle\bigcup_{x_i\in A}\{x:f(x)>x_i\}\subset\{x:f(x)>b\}$ ------------------- (2)
From (1) and (2),
$\displaystyle\{x:f(x)>b\}=\bigcup_{x_i\in A}\{x:f(x)>x_i\}$
The RHS is a union of open subsets of $M$ and is therefore open.
Similarly, one could prove that $\{x:f(x)<b\}$ is open for every real $b$.
This would greatly simplify the problem.
Is my proof correct?
Your proof is fine. Here's a way to do it with sequences: let $\mathbb Q\ni x_n\uparrow x\in \mathbb R.$
Then, $f^{-1}((-\infty,x))=f^{-1}\left ( \bigcup_n(-\infty,x_n) \right )=\bigcup_nf^{-1}((-\infty,x_n))$, which is open.
Repeating this argument for a $x_n\downarrow x$ gives the other half of the claim.