TITLE: What are the values of the following integrals?
QUESTION [5 upvotes]: For each $k = 1,2,3,\dots, $, let $I_k=\left( \frac{1}{k+1}, \frac{1}{k}\right)$, $|I_k| = \frac{1}{k(k+1)}$. Let
  $$g_k(x)=k(k+1)\chi_{I_k} \, : \, \int_0^1 g_k(x)dx=1$$
  for each $k$. Let $f: \mathbb{R}^2 \rightarrow \mathbb{R}$ be defined as follows
  $$f(x,y) := 
\begin{cases}
0, \quad &\text{if}\ (x,y)\not\in[0,1]^2\\
\sum_{k=1}^{\infty}[g_k(x)-g_{k+1}(x)]g_k(y) \quad &\text{if}\ (x,y)\in [0,1]^2
\end{cases}$$
  Find the values of $$\int_0^1\int_0^1f(x,y)dxdy, \, \int_0^1\int_0^1 f(x,y)dydx,\, \text{and}\, \iint_{[0,1]^2}f(x,y)dxdy$$ 

The values of the integrals are supposed to be $1, 0$ and $\infty$ respectively, but I don't know why (I get that both the iterates are $0$). For example:
 \begin{align*}
\int_0^1 \int_0^1 f(x,y)dydx &= \int_0^1 \int_0^1 \sum_{k=1}^{\infty} [g_k(x)-g_k(x)]g_k(y)dydx\\
& =\int_0^1 \sum_{k=1}^{\infty}\int_0^1[g_k(x)-g_{k+1}]g_k(y)didx\\
& =\sum_{k=1}^{\infty} \int_0^1 g_k(y) \int_0^1 [g_k(x)-g_{k+1}(x)]dx dy\\
& = \sum_{k=1}^{\infty}1\cdot 0 = 0
\end{align*} 
and with the same calculations, I get the same result for the other iterate. Where were my mistakes? If someone could point them out and explain to me how to get to the desire result, I'd be more than happy. Thank you!

REPLY [2 votes]: First, for a given $x\in(0,1]$ there exists just one interval $\left(\frac{1}{1+k_0},\frac{1}{k_0}\right]$ that contains $x$ hence the sum $\sum_{k=1}^\infty(g_k(x)-g_{k+1}(x))g_k(y)$ is in fact a sum finite (at most two nonzero terms in the sum), and
$$\eqalign{\int_0^1\left(\sum_{k=1}^\infty(g_k(x)-g_{k+1}(x))g_k(y)\right)dy&=
\sum_{k=1}^\infty(g_k(x)-g_{k+1}(x))\int_0^1g_k(y)dy\cr
&=\sum_{k=1}^\infty(g_k(x)-g_{k+1}(x))=g_1(x)-\lim_{k\to\infty}g_k(x)\cr
&=g_1(x)
}
$$
Thus
$$\int_0^1\left(\int_0^ f(x,y)\right)dy\,dx=\int_0^1g_1(x)dx=1\tag1$$
Second, for a given $y\in(0,1]$ there exists just one interval $\left(\frac{1}{1+k_0},\frac{1}{k_0}\right]$ that contains $y$ hence the sum $\sum_{k=1}^\infty(g_k(x)-g_{k+1}(x))g_k(y)$ is in fact a sum finite (It has one nonzero term), and
$$\eqalign{\int_0^1\left(\sum_{k=1}^\infty(g_k(x)-g_{k+1}(x))g_k(y)\right)dx&=
\sum_{k=1}^\infty\left(\int_0^1(g_k(x)-g_{k+1}(x))dx\right)g_k(y)\cr
&=0
}
$$
Thus
$$\int_0^1\left(\int_0^1 f(x,y)dx\right)dy=0\tag2$$
Finally,
$$\int_{[0,1]^2}\vert f(x,y)\vert dxdy=+\infty$$
Because if this integral were finite then by Fubini's theorem the integrals $(1)$ and $(2)$ would be equal. Note that $\int_{[0,1]^2} f(x,y) dxdy$ is meaningless.$\square$