5. When $n=1,2, \cdots, 2012$, the quadratic function
$$
y=\left(n^{2}+n\right) x^{2}-(2 n+1) x+1
$$

intersects the $x$-axis, and the sum of the lengths of the segments intercepted on the $x$-axis is ( ).
(A) $\frac{2010}{2011}$
(B) $\frac{2011}{2012}$
(C) $\frac{2012}{2013}$
(D) $\frac{2013}{2014}$
5. C.

Solve $\left(n^{2}+n\right) x^{2}-(2 n+1) x+1=0$, we get $x_{1}=\frac{1}{n+1}, x_{2}=\frac{1}{n}$.
Then $d_{n}=\left|x_{1}-x_{2}\right|=\frac{1}{n}-\frac{1}{n+1}$.
Therefore, $d_{1}+d_{2}+\cdots+d_{2012}$
$$
\begin{array}{l}
=\left(1-\frac{1}{2}\right)+\left(\frac{1}{2}-\frac{1}{3}\right)+\cdots+\left(\frac{1}{2012}-\frac{1}{2013}\right) \\
=1-\frac{1}{2013}=\frac{2012}{2013} .
\end{array}
$$