(21) The center of the ellipse $C$ is the origin $O$, with foci on the $y$-axis, the distance from the foci to the corresponding directrix, and the eccentricity are both $\frac{\sqrt{2}}{2}$. The line $l$ intersects the $y$-axis at point $P(0, m)$, and intersects the ellipse $C$ at two distinct points $A$ and $B$, and $\overrightarrow{A P}=\lambda \overrightarrow{P B}$.
(1) Find the equation of the ellipse;
(2) If $\overrightarrow{O A}+\lambda \overrightarrow{O B}=4 \overrightarrow{O P}$, find the range of $m$.
21 (1) Let $C: \frac{y^{2}}{a^{2}}+\frac{x^{2}}{b^{2}}=1(a>b>0)$, and let $c>0, c^{2}=a^{2}-b^{2}$. From the given conditions, we have $\frac{a^{2}}{c}-c=\frac{b^{2}}{c}=\frac{\sqrt{2}}{2}, \frac{c}{a}=\frac{\sqrt{2}}{2}$. Therefore, $a=1, b=c=\frac{\sqrt{2}}{2}$. Hence, the equation of $C$ is $y^{2}+2 x^{2}=1$.
(2) From $\overrightarrow{A P}=\lambda \overrightarrow{P B}$, we get
$$
\begin{array}{l}
\overrightarrow{O P}-\overrightarrow{O A}=\lambda(\overrightarrow{O B}-\overrightarrow{O P}), \\
(1+\lambda) \overrightarrow{O P}=\overrightarrow{O A}+\lambda \overrightarrow{O B},
\end{array}
$$

Thus, $\lambda+1=4, \lambda=3$. Let the intersection points of $l$ with the ellipse $C$ be $A\left(x_{1}, y_{1}\right)$ and $B\left(x_{2}, y_{2}\right)$,
$$
\left\{\begin{array}{l}
y=k x+m \\
2 x^{2}+y^{2}=1
\end{array}\right.
$$

We get
$$
\left(k^{2}+2\right) x^{2}+2 k m x+\left(m^{2}-1\right)=0,
$$

Therefore,
$$
\begin{aligned}
\Delta & =(2 k m)^{2}-4\left(k^{2}+2\right)\left(m^{2}-1\right) \\
& =4\left(k^{2}-2 m^{2}+2\right)>0
\end{aligned}
$$

Then,
$$
x_{1}+x_{2}=\frac{-2 k m}{k^{2}+2}, x_{1} x_{2}=\frac{m^{2}-1}{k^{2}+1} \text {. }
$$

Since $\overrightarrow{A P}=3 \overrightarrow{P B}$, we have $-x_{1}=3 x_{2},\left\{\begin{array}{l}x_{1}+x_{2}=-2 x_{2} \\ x_{1} x_{2}=-3 x_{2}^{2},\end{array}\right.$
Eliminating $x_{2}$, we get
$$
3\left(x_{1}+x_{2}\right)^{2}+4 x_{1} x_{2}=0,
$$

Thus, $3\left(\frac{-2 k m}{k^{2}+2}\right)^{2}+4 \frac{m^{2}-1}{k^{2}+2}=0$, simplifying to
$$
4 k^{2} m^{2}+2 m^{2}-k^{2}-2=0 .
$$

When $m^{2}=\frac{1}{4}$, the above equation does not hold; when $m^{2} \neq \frac{1}{4}$, $k^{2}=\frac{2-2 m^{2}}{4 m^{2}-1}$. From (1), we get $k^{2}>2 m^{2}-2$. Since $\lambda=3$, we have $k \neq 0, k^{2}=\frac{2-2 m^{2}}{4 m^{2}-1}>0$, so $-1<m<$ $-\frac{1}{2}$ or $\frac{1}{2}<m<1$. Therefore, the range of $m$ is $\left(-1,-\frac{1}{2}\right) \cup\left(\frac{1}{2}, 1\right)$.