

Please explain what limits of integration they took for solving $p_i(x)$ and $q_i(x)$.
like for 1st step of $p_i(x)$:
$$\int_\alpha^x 1 \, \mathrm dx = x-\alpha$$
but for 2nd step of $p_i(x)$:
$$\int_\gamma^x -1 \,\mathrm dx = \gamma-x$$
Why did they take this limit? Why did they skipp beta? Please explain! and for $q_i(x)$ as well...
We want to obtain an formula for $p_i$ knowing that $p_i'=h_i$. Of course we use $$p_i(x)=p_i(x_0)+\int_{x_0}^x h_i(t)\,dt \tag1$$ where $x_0$ can be chosen as we wish (as long as we can find $p_i(x_0)$ easily). And we wish to choose $x_0$ to simplify integration: it's better not to have the transition point $\beta$ inside of the interval of integration.
So, when $x\in [\alpha,\beta)$, we pick $x_0=\alpha$ where $p_i(\alpha)=0$. But when $x\in [\beta,\gamma)$, we pick $x_0=\gamma$ where $p_i(\gamma)=\int_{\alpha}^\gamma h_i=0$. This simplifies integration: $p_i(x)=\int_{\gamma}^x -1\,dt = \gamma-x$.
When it comes to $q_i$, we have $$q_i(x)=q_i(x_0)+\int_{x_0}^x p_i(t)\,dt \tag2$$ When $x\in [\alpha,\beta)$, we pick $x_0=\alpha$ where $q_i(\alpha)=0$. When $x\in [\beta,\gamma)$, we pick $x_0=\gamma$ where $q_i(\gamma)=\int_{\alpha}^\gamma p_i=\frac12((\alpha-\beta)^2+(\beta-\gamma)^2)$.