Let $X\subset \mathbb R$ and $f:X\to \mathbb R$ be a function.
I want to show
If $A,B\subset \mathbb R$ satisfy $$X=A\cup B, A\cap B=\emptyset,$$ then
$f$ is continuous $\iff$ $f|_A$, $f|_B$ are both continuous.
I did $\Rightarrow$. So I have to show opposite.
Suppose $f|_A$, $f|_B$ are both continuous.
To show the continuity of $f:X\to \mathbb R$, I'll show $$\forall O\in \mathcal O_{\mathbb R}\ ; \ f^{-1}(O)\in \mathcal O_{\mathbb R}^X,$$ where $\mathcal O_{\mathbb R}$ is Euclidean topology and $\mathcal O_{\mathbb R}^X$ is relative topology, i.e., $\mathcal O_{\mathbb R}^X=\{ X\cap O \mid O\in \mathcal O_{\mathbb R} \}.$
I have $$f^{-1}(O)=(f|_A)^{-1}(O)\cup (f|_B)^{-1}(O).$$
And from the continuity of $f|_A$ and $f|_B$, I have $$(f|_A)^{-1}(O)\in \mathcal O_{\mathbb R}^A,\ (f|_B)^{-1}(O)\in \mathcal O_{\mathbb R}^B.$$ So there exists $O_1, O_2\in \mathcal O_{\mathbb R}$ s.t. $$(f|_A)^{-1}(O)=A\cap O_1,\ (f|_B)^{-1}(O)=B\cap O_2.$$
Then, \begin{align} f^{-1}(O) &=(f|_A)^{-1}(O)\cup (f|_B)^{-1}(O)\\ &=(A\cap O_1) \cup (B\cap O_2) \end{align}
So, to show $f^{-1}(O)\in \mathcal O_{\mathbb R}^X$, I want to say $$(A\cap O_1) \cup (B\cap O_2) =X\cap [\mathrm{an \ element \ of\ } \mathcal O_{\mathbb R}]. \ \cdots (\ast) $$
But I'm stacked here. I don't know how I should show $(\ast)$.