The following is wrong, but the comments are really nice :)
Suppose That on $(a_1, b_1)$, $f$ is a polynomial of degree $N$. This means that in its Taylor series at any point $x \in (a_1, b_1)$, every coefficiant past the $(N+1)$st vanishes.
This must also be true for the border points, $x = a_1$ and $x=b_1$. However, because the intervals are dense in $O$, $a_1$ or $b_1$ lies in the closure of some other interval. The rest is something like an induction: It follows that on every set $(a_n, b_n)$, the coefficients past the $(N+1)$st vanish.
This shows that $f$ is a polynomial, by the fundamental theorem of calculous.