This was CIIM 2021 problem 6. I'm trying to find a solution to this problem considering the inner product
$$\left<f,g\right>=\int_a^b f(x)g(x)dx.$$
Let's work on the case $a=0$, $b=1$ first. Our formulation of the problem now is: prove that there's no continuous function $f:[0,1]\to\mathbb R$ so that $\left<f,x^{2n}\right>>0$ and $\left<f,x^{2n+1}\right><0$ for all $n\in\mathbb N$.
By the Stone-Weierstrass theorem, for all $\epsilon>0$ there exists an $n=n(\epsilon)$ and a polynomial $P$ of degree $n$ so that $|f(x)-P(x)|<\epsilon$ for all $x\in[0,1]$. I think it will be useful to write this using the shifted Legendre polynomials as a base
$$P(x)=\sum_{l=0}^n a_l \widetilde P_l(x).$$
Then $||f-P||<\epsilon^2$. Also from the Cauchy-Schwarz inequality we have $|\left<f,x^k\right>|\leq ||f|| ||x^k||$, and we can multiply $f$ by any constant and it continues having the desired properties, so without loss of generality take $||f||=1$, so we have $|\left<f,x^k\right>|\leq \frac 1{k+1}$. The problems now seem to be that the theorem doesn't give a bound on how large $n$ needs to be, and the inverse transform back to the canonical basis (i.e. finding $k_l$ so that $x^n=\sum_{l=0}^n k_l\widetilde P_l(x)$) doesn't seem to have an easy pattern.
For $n \in \mathbb N$ we have that $$\sigma_n(x) = \frac {x^n \exp(-x)}{n!}$$ is a unimodular probability density function on $\mathbb R_{\geq 0}$ with expectation and variance both equal to $n+1$. Let $\alpha \in (a,b)$ then $$\sigma_n(\alpha; x) = \frac {n+1}{\alpha} \sigma_n\left(\frac {(n+1) x}{\alpha}\right)$$ has expectation $\alpha$ and variance $\alpha^2/(n+1)$. This means that for $n \to \infty$ these functions will have an ever narrower, high peak at $x=\alpha$ and tend uniformly to zero at any given minimal distance from $\alpha$. (Loosely speaking, they tend to the distribution $\delta(x - \alpha)$.)
Now the coefficients of the series for $\exp(-x)$ have alternating signs. Therefore the integral $$I_n(\alpha) = \int_a^b f(x) \sigma_n(\alpha; x) \mathrm dx$$ is positive for even $n$ and negative for odd $n$. But $\lim_{n \to \infty} I_n(\alpha) = f(\alpha)$ so $f$ must be identically zero on $[a, b]$. But then $f$ then doesn’t satisfy its requirements.