9. (16 points) Given the sequence $\left\{a_{n}\right\}$ satisfies:
$$
a_{1}=1,\left|a_{n+1}-a_{n}\right|=p^{n}(n=1,2, \cdots) \text {, }
$$

and $\left\{a_{2 n-1}\right\}$ is a monotonically increasing sequence, $\left\{a_{2 n}\right\}$ is a strictly monotonically decreasing sequence. Find the general term formula of the sequence $\left\{a_{n}\right\}$.
Given that
$p \geqslant 0$ and $a_{n+1}-a_{n}= \pm p^{n}(n \geqslant 1)$ holds, where the sign $\pm$ depends on $n$. Therefore, we can set
$a_{n+1}-a_{n}=\alpha(n) p^{n}(\alpha(n)=-1$ or 1$)$.
Thus, $a_{n}-a_{n-1}=\alpha(n-1) p^{n-1}$.
Then, $a_{n+1}-a_{n-1}=p^{n-1}(p \alpha(n)+\alpha(n-1))$.
Since $\left\{a_{2 n-1}\right\}$ is an increasing sequence and $\left\{a_{2 n}\right\}$ is a decreasing sequence, when $n$ is even, we have
$$
a_{n+1}-a_{n-1}=p^{n-1}(p \alpha(n)+\alpha(n-1))>0 \text {; }
$$

When $n$ is odd, we have
$$
a_{n+1}-a_{n-1}=p^{n-1}(p \alpha(n)+\alpha(n-1))<0 \text {; }
$$

(1) If $p=0$, then $a_{n+1}-a_{n}=0$, which implies $a_{n}=1$.

(2) If $p=1$, then $a_{n+1}-a_{n}=\pm 1$. Since $\left\{a_{2 n-1}\right\}$ is increasing and $\left\{a_{2 n}\right\}$ is decreasing, we have
$$
a_{n+1}-a_{n}=(-1)^{n} \quad (n \in \mathbf{Z}_{+}).
$$
Thus,
$$
a_{n}=a_{1}+\left(a_{2}-a_{1}\right)+\left(a_{3}-a_{2}\right)+\cdots+
\left(a_{n}-a_{n-1}\right)
=1-1+1+\cdots+(-1)^{n-1}
=\frac{1+(-1)^{n-1}}{2}.
$$

(3) If $0<p<1$, then $a_{n+1}-a_{n}=(-1)^{n} p^{n} \quad (n \in \mathbf{Z}_{+})$.
Thus,
$$
a_{n}=a_{1}+\left(a_{2}-a_{1}\right)+\left(a_{3}-a_{2}\right)+\cdots+
\left(a_{n}-a_{n-1}\right)
=1-p+p^{2}+\cdots+(-1)^{n-1} p^{n-1}
=\frac{1-(-p)^{n}}{1+p}.
$$

(4) If $p>1$, similarly to (3), we have
$$
\begin{array}{l}
a_{n+1}-a_{n}=(-1)^{n} p^{n}\left(n \in \mathbf{Z}_{+}\right) \text {. } \\
\text { Hence } a_{n}=a_{1}+\left(a_{2}-a_{1}\right)+\left(a_{3}-a_{2}\right)+\cdots+ \\
\left(a_{n}-a_{n-1}\right) \\
=1-p+p^{2}+\cdots+(-1)^{n-1} p^{n-1} \\
=\frac{1-(-p)^{n}}{1+p} \text {. } \\
\end{array}
$$

In summary, the general term formula of the sequence is
$$
a_{n}=\left\{\begin{array}{ll}
1+p \cdot \frac{1-(-p)^{n-1}}{1+p}, & 01 .
\end{array}\right.
$$