I found that problem pretty cool, so I solved it and I wanted to formalise a proof and I figured, since the editorial isn't out yet I may as well give a formal proof of necessary and sufficient conditions for $$$a$$$ to exist. If there is an easier way to prove it let me know, I'm curious. Once you have the necessary and sufficient conditions, you can just check them, if they hold print(YES) (it'll work since they're sufficient), if they don't hold, print(NO) (it'll work because they're necessary).
Let $$$p$$$ and $$$s$$$ be two sequences of integers of size $$$n \gt 1$$$. I'm looking for necessary and sufficient conditions such that we can find a sequence $$$a$$$ of size $$$n$$$ such that we can write for all $$$1 \leq i \leq n$$$, $$$p_i$$$ as $$$\text{GCD}(a_1, a_2, ..., a_i)$$$ and $$$s_i$$$ as $$$\text{GCD}(a_i, a_{i+1}, ..., a_n)$$$.
Necessary conditions:
Suppose we do have a sequence $$$a$$$ of size $$$n$$$ such that we can write for all $$$1 \leq i \leq n$$$, $$$p_i$$$ as $$$\text{GCD}(a_1, a_2, ..., a_i)$$$ and $$$s_i$$$ as $$$\text{GCD}(a_i, a_{i+1}, ..., a_n)$$$.
By definition of the GCD, $$$\forall i \in {1, ..., n-1 } : p_{i+1} | p_i$$$
Similarly, $$$\forall i \in {1, ..., n-1 } : s_i | s_{i+1}$$$
$$$p_n = s_1$$$ (they're both the GCD of the whole array)
$$$p_i | a_i$$$ and $$$s_i | a_i$$$, so $$$\text{LCM}(p_i, s_i) | a_i$$$.
It is easy to show that it is not necessary that $$$a_i = \text{LCM}(p_i, s_i)$$$, e.g. with p=(12,12,6); s=(6,6,6); a=(12,24,6). We have $$$\text{LCM}(p_2, s_2) = 12 \neq a_2$$$ but $$$\text{GCD(a_1)} = 12 = p_1$$$, $$$\text{GCD(a_1, a_2)} = 12 = p_2, ...$$$.
How can we turn $$$\text{LCM}(p_i, s_i) | a_i$$$ into a useful necessary condition? $$$p_i = \text{GCD}(p_{i-1}, a_i) = \text{GCD}(p_{i-1}, k_i * \text{LCM}(p_i, s_i))$$$. Since $$$p_i$$$ divides both terms, we can rewrite this as $$$1 = \text{GCD}(p_{i-1}/p_{i}, k_i * \text{LCM}(p_i, s_i) / p_i)$$$. Since $$$p_{i-1}/p_{i}$$$ and $$$k_i * \text{LCM}(p_i, s_i) / p_i$$$ are coprime, $$$p_{i-1}/p_{i}$$$ and $$$\text{LCM}(p_i, s_i) / p_i$$$ also are (the second term is an integer so all good!). Here is our useful necessary condition: $$$p_{i-1}/p_{i}$$$ and $$$\text{LCM}(p_i, s_i) / p_i$$$ need to be coprime.
Proof that these conditions are sufficient:
Suppose we have $$$p$$$ and $$$s$$$ satisfying all the above conditions. Let's prove that there is a sequence $$$a$$$ of size $$$n$$$ such that we can write for all $$$1 \leq i \leq n$$$, $$$p_i$$$ as $$$\text{gcd}(a_1, a_2, ..., a_i)$$$ and $$$s_i$$$ as $$$\text{GCD}(a_i, a_{i+1}, ..., a_n)$$$.
Let $$$\forall i \in {1, ..., n } : a_i = \text{LCM}(p_i, s_i)$$$
- Let's prove $$$p_1 = \text{GCD}(a_1)$$$. Since $$$p_n | p_1$$$, and $$$p_n = s_1$$$, $$$s_1 | p_1$$$, so $$$\text{LCM}(p_1, s_1) = p_1$$$. But $$$\text{LCM}(p_1, s_1) = a_1$$$. So $$$p_1 = a_1 = \text{GCD}(a_1)$$$
- Let's prove that $$$\forall i \in {2, ..., n } : p_i = \text{GCD}(a_1, a_2, ..., a_i)$$$. We can re-write this as we want to prove $$$p_i = \text{GCD}(p_{i-1}, a_i)$$$. We can re-write this as we want to prove $$$p_i = \text{GCD}(p_{i-1}, \text{LCM}(p_i, s_i))$$$. We can rewrite this as we want to prove $$$1 = \text{GCD}(p_{i-1}/p_i, \text{LCM}(p_i, s_i)/p_i)$$$. We can re-write this that way because $$$p_i | p_{i-1}$$$ and $$$p_i | \text{LCM}(p_i, s_i)$$$ so everything is an integer all good. But we don't need to prove that since this is one of our above conditions.
A similar proof can be conducted for $$$s_i$$$. It's worth noting no extra “suffix” condition is missing, our 4 necessary conditions are enough (it'd be easier for the proof to add a necessary condition, but it's more fun to prove that it is redundant/useless). We want to prove $$$\forall i \in {1, ..., n } : s_i = \text{GCD}(a_i, a_{i+1}, ..., a_n)$$$. We can re-write this as we want to prove $$$s_i = \text{GCD}(s_{i+1}, a_i)$$$. This can be rewritten as $$$1 = \text{GCD}(s_{i+1}/s_i, a_i/s_i)$$$. This can be rewritten as $$$1 = \text{GCD}(s_{i+1}/s_i, \text{LCM}(p_i, s_i)/s_i)$$$. This can be rewritten as $$$1 = \text{GCD}(s_{i+1}/s_i, a_i/s_i)$$$. This coprimality can be rewritten as $$$q|s_{i+1}/s_i = \gt q \nmid a_i/s_i$$$ for all prime $$$q$$$. Let $$$q$$$ be a prime. Let $$$\pi_i$$$ be the multiplicity of $$$q$$$ in the prime factorisation of $$$p_i$$$ and $$$\sigma_i$$$ in $$$s_i$$$ and $$$\alpha_i$$$ in $$$a_i$$$. We want to prove $$$\forall i \in {1, ..., n-1} \; \sigma_{i+1} \gt \sigma_i = \gt \alpha_i = \sigma_i$$$.
If $$$\sigma_1 = \sigma_n$$$ there is nothing to prove because we know that $$$\sigma_i$$$ is non-decreasing (left term of the implication we want to prove is always False).
So suppose $$$\sigma_1 \lt \sigma_n$$$. $$$\pi_n = \sigma_1 \lt \sigma_n$$$ and $$$\pi_1 \geq \pi_n = \sigma_1$$$ so there is a $$$k \lt n$$$ such that $$$\forall i, 1 \leq i \leq k \; \sigma_i \leq \pi_i$$$ and $$$\forall i, k \lt i \leq n \; \sigma_i \gt \pi_i$$$. Thus for $$$i \gt k$$$, $$$\pi_i \lt \alpha_i$$$. But $$$p_{i-1}/p_{i}$$$ and $$$\text{LCM}(p_i, s_i) / p_i$$$ are coprime. So $$$\pi_{i-1} \gt \pi_i = \gt \alpha_{i} = \pi_{i}$$$. So, $$$\pi_{i-1} = \pi_i$$$ for $$$i \gt k$$$. So $$$\sigma_1 = \pi_n = ... = \pi_k \geq \sigma_k \geq ... \geq \sigma_1$$$. Therefore, equality everywhere. Hence $$$\sigma_i = \sigma_{i+1}$$$ for $$$1 \leqslant i \lt k$$$, and $$$\alpha_i = \sigma_i$$$ for $$$k \leqslant i \leqslant n$$$ ($$$\sigma_i \gt \pi_i$$$ for $$$i \gt k$$$ and $$$\sigma_k = \pi_k$$$, thus $$$\forall i \in {1, ..., n-1} \; \sigma_{i+1} \gt \sigma_i = \gt \alpha_i = \sigma_i$$$ (A => B is the same as non A or B).
EDIT => added the proof for $$$s_i$$$