If the sets $A=\{x\in E, f(x)<\lambda\}$ and $B=\{x\in E, f(x)>\lambda\}$ are open, then $f$ is continuous I have that $f: (E,\theta)\rightarrow (\mathbb{R},|.|)$ an application, if we have that for all $\lambda\in \mathbb{R}$ the two sets $A=\{x\in E, f(x)<\lambda\}$ and $B=\{x\in E, f(x)>\lambda\}$ are open.
How to prove that f is continuous?
Can I say that $A=f^{-1}(]-\infty,\lambda[)$ and $B=f^{-1}(]\lambda,+\infty[)$ then the preimage of an open sets is open so $f$ is continuous.
But why we have to use the two sets $A$ and $B$ ?
Thank you
 A: Let $U$ open in $(\mathbb{R},|\cdot|)$. If $U=\emptyset$ or $U=\mathbb{R}$, then  a straightforward argument shows $f^{-1}(U)\in\theta$.
Now, let $(a,b)\subseteq\mathbb{R}$. If we prove that $f^{-1}((a,b))\in\theta$, we finish.
But $(a,b)=(-\infty,b)\cap(a,\infty)$. Then $f^{-1}(a,b)=f^{-1}((-\infty,b)\cap(a,\infty))=f^{-1}((-\infty,b))\cap f^{-1}((a,\infty))$.
Now, by hypothesis, both of $f^{-1}((-\infty,b))$ and $f^{-1}((a,\infty))$ are open, and since finite intersection of open sets is an open set, $f^{-1}(a,b)$ is open.
A: The system $\mathcal S=\{(-\infty,b), (a,\infty); a,b\in\mathbb R\}$ is a subbase for the usual Euclidean topology on $\mathbb R$. (This means that all elements of $\mathcal S$ are open and if you take intersections of finitely meany elements from $\mathcal S$, you get a basis. And, indeed, such intersections are in this case precisely the open intervals or empty set.)
In general we have the following:

Let $X$, $Y$ be a topological space, $f\colon X\to Y$ be a function and $\mathcal S$ be a subbase for the $Y$. The function $f$ is continuous if and only if $f^{-1}(U)$ is open for each $U\in\mathcal S$.

The proof of this fact is not difficult.

Proof. $\boxed{\Rightarrow}$ This implication is clear, since the sets from $\mathcal S$ are open.
$\boxed{\Leftarrow}$ Let $\mathcal B$ be the system of all finite intersections of sets from $\mathcal S$. 
  If $B\in\mathcal B$ then $B$ has the form
  $$B=\bigcap_{i=1}^n U_i$$
  for some $U_i\in\mathcal S$, $i=1,\dots,n$. Since
  $$f^{-1}[B]=\bigcap_{i=1}^n f^{-1}[U_i],$$
  we get that $f^{-1}[B]$ is open for each $B\in\mathcal B$.
Now we know that preimages of all basic sets are open. We also know that open sets are precisely unions of sets from $\mathcal B$. So if 
  $$O=\bigcup_{i\in I} B_i$$
  for some $\{B_i; i\in I\}\subseteq\mathcal B$, then we see that
  $$f^{-1}[O]=\bigcup_{i\in I} f^{-1}[B_i]$$
  is open. $\square$

In the above proof we have used the fact that preimages preserve unions and intersections. See, for example:
Overview of basic results about images and preimages, What are the strategies I can use to prove $f^{-1}(S \cap T) = f^{-1}(S) \cap f^{-1}(T)$?, 
Union of preimages and preimage of union (and some other posts.)
A: $f$ is continuous if and only if  the preimage by $f$ of ANY open set is open. Then it suffices to remark that $]a, b[= ]a, \infty[ \cap ]-\infty, b[.$ 
