$f$ convex, $g$ concave and increasing, $\int_0^1 f = \int_0^1 g$, then $\int_0^1(f)^2 \geq \int_0^1(g)^2$

It will be easy to answer the following question first: Assume that $f(x)$ is convex, $f(0)=0$, $f(x)\geq 0$ and $\int_{0}^{1}f(x)dx=M>0$ is fixed. Which function makes the integral $$ \int_{0}^{1}f(x)^{2}dx $$ as small as possible? We will prove that linear function is the optimizer, i.e. $f(x) = kx = 2Mx$ gives the answer. To prove this, we need a lemma:

Lemma. Let $f:[0, 1]\to [0, \infty)$ be a convex continuous function with $f(0)=0$. Then we have $$ \int_{0}^{1}xf(x)dx\geq \frac{2}{3}\int_{0}^{1}f(x)dx $$

This is actually a contest problem I saw before. We will show this later.

Assume that the lemma holds. Then we have $$ 0\leq \int_{0}^{1}(f(x)-2Mx)^{2}dx = \int_{0}^{1}f(x)^{2} -4M\int_{0}^{1}xf(x)dx + \frac{4}{3}M^{2} \leq \int_{0}^{1}f(x)^{2}dx - \frac{4}{3}M^{2} $$ so $\int_{0}^{1}f(x)^{2}dx \geq \frac{4}{3}M^{2}$, where the equality holds for $f(x)=2Mx$. Similarly, the reversed inequality holds for the concave function $g(x)$ with same condition, so we get $$ \int_{0}^{1}f(x)^{2}dx \geq \frac{4}{3}M^{2} \geq \int_{0}^{1}g(x)^{2}dx. $$


Proof of Lemma. Since $f(x)$ is convex, we have $$\int_{0}^{x}f(t)dt \leq \frac{1}{2}xf(x)$$ for any $x$. (Consider the triangle with vertices $(0, 0), (x, 0), (x, f(x))$.) Then \begin{align*} \frac{1}{2}\int_{0}^{1}xf(x)dx &\geq \int_{0}^{1}\int_{0}^{x}f(t)dtdx \\ &=\int_{0}^{1}\int_{t}^{1}f(t)dxdt \,\,\quad(\text{Fubini's theorem})\\ &=\int_{0}^{1}(1-t)f(t)dt \\ &= \int_{0}^{1}f(x)dx - \int_{0}^{1}xf(x)dx \end{align*} and we get the inequality.