TITLE: Improper integral diverges
QUESTION [35 upvotes]: Let a real-valued function $f$ be continuous on $[0,1].$ Then there exists a number $a$ such that the integral
$$\int_0^1\frac 1 {|f(x)-a|}\, dx
$$ diverges. How to prove that statement?

REPLY [15 votes]: Here's a proof that $\int_0^1\frac1{\lvert f(x)-a\rvert}dx = \infty$ for every $a$ in the image of $f$ and outside of a meagre set. In particular, if $f$ is not constant, then there are uncountably many such $a$ in every neighborhood of the image of $f$. [Note: I also agree that user72694's proof works fine, and is completely independent of the proof I'll give here.]
First, define $g(a)$ to be the given integral, and let $[a_0,a_1]$ be the image of $f$. Assuming that $f$ is non-constant, we have $a_0 < a_1$. Letting $b_0 < b_1$ be in $[a_0,a_1]$ then Fubini's theorem gives,
$$
\int_{b_0}^{b_1}g(a)\,da=
\int_{b_0}^{b_1}\!\!\!\int_0^1\frac1{\lvert f(x)-a\rvert}\,dxda
=\int_0^1\!\!\!\int_{b_0}^{b_1}\frac1{\lvert f(x)-a\rvert}\,dadx=\infty.
$$
Here, the integral of $1/\lvert f(x)-a\rvert$ wrt $a$ is infinite whenever $f(x)$ is in $[b_0,b_1]$ (because $1/x$ is not integrable at the origin), which happens for $x$ in a nontrivial interval, so the double integral is infinite. This means that $g$ is not integrable (and, hence, is unbounded) in any nontrivial interval $[b_0,b_1]$ in the image of $f$.
Next, for each $K > 0$, set $S_K=\lbrace a\in[a_0,a_1]\colon g(a) > K\rbrace$. As $g$ is unbounded in the neighborhood of any point, the set $S_K$ is dense in $[a_0,a_1]$. Furthermore, $S_K$ is open for each positive $K$. To see this, note that $g_n(a)\equiv\int_0^11_{\lbrace\lvert f(x)-a\rvert > 1/n\rbrace}/\lvert f(x)-a\rvert dx$ is a sequence of continuous functions increasing to $g$, so $g$ is lower semicontinuous.
Hence, we have
$$
\left\lbrace a\in[a_0,a_1]\colon g(a)=\infty\right\rbrace=\bigcap_{n=1}^\infty S_n,
$$
which is a countable intersection of dense open sets in $[a_0,a_1]$ so, by definition, its complement is meagre.