Let $f,g:[a,b]\to\mathbb R$ continuous functions, with $f(x)\leq g(x)$ for every $x\in[a,b]$. Define $\varphi:[a,b]\to\mathbb R$ by $$ \varphi(x)= \left\{ \begin{array}{cc} f(x) &,\mbox{ if } x\in\mathbb Q\cap[a,b],\\ g(x) &,\mbox{ if } x\not\in\mathbb Q\cap[a,b]. \end{array} \right. $$ Prove that $$ \tag 1 \underline{\int_a^b} \varphi(x)dx = \int_a^b f(x)dx\quad \mbox{ and }\quad \overline{\int_a^b} \varphi(x)dx = \int_a^b g(x)dx. $$ Conclude that $\varphi$ is integrable if and only if $f=g$.
I already proved $(1)$ and $f=g \Longrightarrow \varphi$ integrable is obvious. I need help to prove that $\varphi$ integrable $\Longrightarrow f=g$
If $\phi$ is integrable then $\displaystyle \int_a^b f(x) \, dx = \int_a^b g(x) \, dx$, or equivalently, $\displaystyle \int_a^b g(x) - f(x) \, dx = 0.$ If there is a single point $x_0 \in (a,b)$ with $f(x_0) < g(x_0)$, continuity gives you an $\epsilon > 0$ satisfying $$(x_0 - \epsilon, x_0 + \epsilon) \subset (a,b)$$ and $f(x) < g(x)$ for all $x \in (x_0 - \epsilon, x_0 + \epsilon)$. Then $$0 = \int_a^b g(x) - f(x) \, dx \ge \int_{x_0 - \epsilon}^{x_0 + \epsilon} g(x) - f(x) \, dx > 0 $$ which is a contradiction. Thus $f(x) = g(x)$ for all $x \in (a,b)$ and by continuity, for all $x \in [a,b]$ too.