When is a continuous function also a bijective function? To begin with, I would like to  set forth a property of continuous functions:

There doesn't exist a continuous function $f$ on $\mathbb{R}$ such that $f|_{\mathbb{R}\setminus \mathbb{Q}} : \mathbb{R}\setminus \mathbb{Q} \rightarrow f\left( \mathbb{R}\setminus \mathbb{Q} \right)$ is a bijection and $f|_{\mathbb{Q}} : \mathbb{Q} \rightarrow f\left(  \mathbb{Q}\right)$ is not a bijection.

Hence, if $f$ is a continuous function on $\mathbb{R}$ and $f|_{\mathbb{R} \setminus \mathbb{Q}}$ is a bijection, then $f|_{\mathbb{Q}}$ must be a bijection too. Motivated by this, My question is in the following:

Suppose that $f \in C(\mathbb{R})$ and $f|_{\mathbb{R}\setminus \mathbb{Q}}$ is a bijection from $\mathbb{R}\setminus \mathbb{Q}$ onto $f\left( \mathbb{R}\setminus \mathbb{Q} \right)$. Then, can we come to a conclusion that $f$ is a bijection from $\mathbb{R}$ onto $f\left( \mathbb{R} \right)$ ?

 A: Your conjecture is correct.  First, note that any function is trivially surjective onto its image, so the real question is injectivity.
To prove injectivity, suppose by way of contradiction that there existed  $a \neq b$, $f(a) = f(b)$; without loss of generality, $a < b$.  Then we note that there exists $c \in (a, b)$ with $f(c) \neq f(a)$: for of course, if $f$ was constant on $[a, b]$, then $\left. f \right\vert_{\mathbb{R} \setminus \mathbb{Q}}$ would not be injective.  By replacing $f$ with $-f$ if necessary, we may assume without loss of generality that $f(a) = f(b) < f(c)$.
By the Intermediate Value Theorem and continuity of $f$, the interval $(f(a), f(c))$ is a subset of the image of $f$ on $(a, c)$, or $f((a, c))$.  Yet clearly $f((a, c)) = f((a, c) \cap (\mathbb{R} \setminus \mathbb{Q})) \cup f((a, c) \cap \mathbb{Q})$, and $f((a, c) \cap \mathbb{Q})$ is the image of a countable set, hence countable; call it $C_1$.  
A rule of sets says that if $S \subseteq T \cup U$, then $S \setminus U \subseteq T$, for $$
S \setminus U \subseteq (T \cup U) \setminus U = T \setminus U \subseteq T.
$$
By this logic, $(f(a), f(c)) \setminus C_1 \subseteq f((a, c) \cap (\mathbb{R} \setminus \mathbb{Q}))$; that is, $f((a, c) \cap (\mathbb{R} \setminus \mathbb{Q}))$ covers all but countably many elements of $(f(a), f(c))$.  
Yet by the same logic applied to $(c, b)$, there is some other countable set $C_2$ such that $(f(a), f(c)) \setminus C_2 \subseteq f((c, b) \cap (\mathbb{R} \setminus \mathbb{Q}))$. 
Therefore, $(f(a), f(c)) \setminus (C_1 \cup C_2)$ is contained in both $f((a, c) \cap (\mathbb{R} \setminus \mathbb{Q}))$ and $f((c, b) \cap (\mathbb{R} \setminus \mathbb{Q}))$.  Yet the finite union of countable sets is countable, and $(f(a), f(c))$ is uncountable, so certainly $(f(a), f(c)) \setminus (C_1 \cup C_2)$ is nonempty (in fact, uncountable!), so contains some $y$.  By definition of the image, there exists $u \in (a, c) \cap (\mathbb{R} \setminus \mathbb{Q})$ with $f(u) = y$; similarly, there exists $v \in (c, b) \cap (\mathbb{R} \setminus \mathbb{Q})$ with $f(v) = y$.  Clearly $u < c < v$.  Yet $f$ is injective on $\mathbb{R} \setminus \mathbb{Q}$.  Contradiction.  
Note that $\mathbb{Q}$ was not particularly special here; any countable [or meager/Baire-first-category, or Lebesgue-measure-zero] set would do.  Note also that it was easiest to just show that there was a "large" set of overlap in $\mathbb{R} \setminus \mathbb{Q}$ as soon as injectivity was violated anywhere.
A: Because we are concerned about bijecting on the image of $f$, it is sufficient to  investigate the injectivity of $f$. For contradiction, assume $f$ is not injective. Therefore, $f$ is neither strictly increasing nor strictly decreasing. (A continuous, injective function $f: \mathbb{R} \to \mathbb{R}$ is either strictly increasing or strictly decreasing.).
Since $f$ is neither strictly increasing nor strictly decreasing, there are a few possibilities for the behavior of $f$. However, each proof will proceed similarly to this: Suppose there exists $x,y,z \in \mathbb{R}$ such that $x < y < z$ with $f(x) > f(y)$ and $f(y) < f(z)$. Without loss of generality, assume $f(z) \geq f(x)$. 
Recall that any function $g: U \to V$ is surjective, or onto $V$ if for each $v \in V$ there exists $u \in U$ such that $g(u) = v$. 
Let $A = (f(y),f(x)) \subseteq(f(y),f(z))$. By the Intermediate Value Theorem, for all $t \in A$, there exists $c_1 \in (x,y)$ and $c_2 \in (y,z)$ such that $f(c_1) = f(c_2) = t$. Let $$C_1 = \{c_1 \in (x,y): f(c_1) = t \in A\text{, } \forall t \in A\}$$ $$C_2 = \{c_2 \in (y,z): f(c_2) = t \in A\text{, } \forall t \in A\}$$
Therefore, this shows that $f:C_1 \to A$ and $f:C_2 \to A$ are surjective. Recall that because $A$ is an open interval of the real line, it is uncountable so $C_1$ and $C_2$ must be uncountable.
Next, we want to show that there exists $C_1' \subseteq C_1$ and $C_2' \subseteq C_2$ such that $f(C_1') = f(C_2') = A$, one-to-one on the domains. In other words, we want to restrict the domain to get an injection by removing all but one of the elements in both $C_1$ and $C_2$ that have the same mapping (we aren't worried about continuity at the moment). This is a straight-forward application of the Axiom of Choice that can be skipped. Therefore, I'll only show it for $C_1$ in Lemma 1.
But before that, note that for all $t \in A$ such that $f(c_1) = f(c_2) = t$, both $c_1$ and $c_2$ cannot both be in $\mathbb{R} \backslash \mathbb{Q}$. Otherwise, $f|_{\mathbb{R} \backslash \mathbb{Q}}$ is not injective, which is a contradiction. This is important because it guarantees that removing the duplicates for any particular $t$ won't get rid of the both the rational mappings from $C_1$ and $C_2$, which is necessary for the final contradiction.

Lemma 1: Consider the collection of all sets $D_t = \{c \in C_1\mid \exists c' \in C_1 : f(c) = f(c') = t\}$ such that $t \in A$. By the Axiom of Choice, there exists a set $D$ that contains  exactly one element from every set in the collection. Then let $$C_1' = \left(C_1 \backslash \bigcup_{t\in A}D_t\right) \cup D $$ Moreover, for any $t \in A$, at most only one element in $D_t$ can be irrational. Otherwise, $f$ is not injective on $\mathbb{R}\backslash \mathbb{Q}$.

Let $C = \{\langle c_1,c_2\rangle \in C_1' \times C_2' : f(c_1) = f(c_2) \}$ (using $\langle,\rangle$ so as not to confuse the ordered pair as an interval). Then $C$ is just the set of pairs of elements in $C_1$ and $C_2$ found by the intermediate value theorem, with elements of identical mapping removed. We already proved above that every pair must have at least one rational number. 
Next, I'll show that no rational number appears twice. Obviously same rational number cannot be in one pair because $C_1$ and $C_2$ are disjoint intervals. So without loss of generality, suppose $\langle c, a \rangle$ and $\langle c, b \rangle$ are elements of $C$ such that $c \in \mathbb{Q}$. By the definition of $C$, $f(c) = f(a) = f(b)$. However, $a,b \in C_2'$, and $C_2'$ has no two elements that have the same mapping, by it's construction in Lemma 1. Therefore, $a = b$ and the two pairs are the equal.
So, we have arrived at the fundamental contradiction: every pair in $C$ contains a unique rational number so the set $C$ is countable. Likewise, $C_1'$ is then countable, because every element is in one pair of $C$. Recall that $f:C_1' \to A$ is surjective. We now see that this is impossible, because it is a function from a countable set $C_1'$, to the uncountable open interval $A$.

P.S. Just another way to see user52733's answer.
EDIT 
I've updated my answer significantly. Travis Wang pointed out that my previous proof made a pretty serious oversight. I think I corrected it, but now my proof is probably harder than the other answer. Oh well, I learned a lot. Thanks for the feedback.
