The piecewise function is a test for rationality.
The lower sum of some function f with respect to its partition P, $L(P,f)$ is defined as the sum of all non overlapping rectangular units contained by the function's area and the line $y=0$, created by partitioning some bounded interval.
If we define $m_i=inf\left\{f(x):x\in [x_{i-1},x_i]\right\}$ for $i = 1,2,...,n$, then the lower sum $L(P,f)$ is defined as:
$$\sum_{k=1}^nm_i(x_i-x_{i-1}) $$
So, considering your given function, x takes on irrational values much more often than it does rational, as the reals is more densely covered with irrationals than rationales. So $L(P,f)=0$
If we define $M_i=sup\left\{f(x):x\in [x_{i-1},x_i]\right\}$ for $i = 1,2,...,n$, then the upper sum $U(P,f)$ is defined as:
$$\sum_{k=1}^nM_i(x_i-x_{i-1}) $$
When x is rational, its mapping $x\rightarrow x$ has identical input and output function values. This is analogous to the function $f(x)=x$, for $x\in \mathbb{Q}.$
So if we partition a set into two subintervals with three distinct elements $P=\left\{0,\frac 12, 1\right\}$ and because x is bounded by the interval $[0,1]$ as specified, the upper sum is as follows:
$$U(P,f)=\sum_{k=1}^nM_i(x_i-x_{i-1}) =1(1- \frac 12)+ \frac 12(\frac 12-0)=\frac 34.$$
The upper sum takes on this value for the specified partition, because when x is rational, the function increases monotonically on the interval $[0,1]$.
First, it is a sufficient condition.
As long as $f$ is bounded on $[0,1]$, the upper and lower sums corresponding to arbitrary partitions are bounded. Let $\mathcal{P}$ denote the set of all partitions of $[0,1].$ Consequently, the sets $\{L(P,f): P \in \mathcal{P}\}$ and $\{U(P,f): P \in \mathcal{P}\}$ are bounded, and this guarantees the existence of
$$\underline{\int}_0^1 f(x) \, dx = \sup_{P \in \mathcal{P}}\, L(P,f), \\ \overline{\int}_0^1 f(x) \, dx = \inf_{P \in \mathcal{P}}\, U(P,f) , $$
which are called the lower and upper integrals.
Given any regular partition $D_n$ we have
$$L(D_n,f) \leqslant \underline{\int}_0^1 f(x) \, dx \leqslant \overline{\int}_0^1 f(x) \, dx \leqslant U(D_n,f).$$
The central inequality follows because for any partitions $P$ and $Q$ we have $L(P,f) \leqslant U(Q,f)$ (take a common refinement of the partitions to show this) and, thus $\sup_{P \in \mathcal{P}} \,L(P,f) \leqslant \inf_{Q \in \mathcal{P}} \,U(Q,f)$.
Hence,
$$0 \leqslant \overline{\int}_0^1 f(x) \, dx - \underline{\int}_0^1 f(x) \, dx \leqslant U(D_n,f) - L(D_n,f).$$
The right-hand side converges to $0$ as $n \to \infty$, by hypothesis, which implies that $f$ is integrable since we must have
$$\underline{\int}_0^1 f(x) \, dx = \overline{\int}_0^1 f(x) \, dx, $$
where the common value of lower and upper integrals is by definition the value of the integral.
To show it is a necessary condition, consider
$$\left|U(D_n,f) - L(D_n,f) \right| \leqslant \left|U(D_n,f) - \int_0^1 f(x) \, dx \right| + \left|L(D_n,f) - \int_0^1 f(x) \, dx \right|.$$
The two terms on the RHS go to zero as $n \to \infty$. This is a consequence of the equivalent condition for integrability where for arbitrary Riemann sums corresponding to tagged partitions we have
$$\tag{*}\int_0^1 f(x) \, dx = \lim_{\|P\| \to 0} S(P,f).$$
Here $\|P\| = \max_{1 \leqslant j \leqslant n} (x_j - x_{j-1})$ is the norm of the partition $P = (x_0,x_1, \ldots, x_n)$ and, clearly, $\|D_n\| \to 0$ if and only if $n \to \infty$.
It takes a bit of effort to prove the equivalence of $(*)$ to the definition of the Riemann integral in terms of partition refinement or the Darboux approach. It has been shown a number of times on this site including here.
Best Answer
Start with the definition. Partition the interval first; as the function is constant except on the boundary, this partition doesn't really matter at all. (Beyond the fact that this will turn out to be Riemann integrable, in which case it really won't matter.) Given $\epsilon>0$, we can just take $0 < \epsilon < x_2 < ... < x_{n-1} < 1$ as our partition, and say the difference between the $x_n$ gets small.
On every interval, the supremum and infimum of $f$ is 1, except on the first. Here, the sup is 3, while the inf is 1. But the width of the interval is $\epsilon$, making the contribution to the upper sum just $3\epsilon$. The contribution everywhere else is $1-\epsilon$. The lower sum is just 1.
Given $\epsilon$ can be made arbitrarily small, the integral converges, showing this function is Riemann integrable with an integral of 1.