Suppose I have a black-box unitary $U_p$ which is described as follows: given a finite probability distribution $p:\{1,\ldots,n\}\rightarrow \mathbb{R}_{\geq0}$, where $\sum_{x=1}^n p(x)=1$, the action of the black box on a basis is given by $$U_p:|x\rangle|0\rangle\mapsto |x\rangle |p(x)\rangle,$$ where I am assuming I can encode each $p(x)$ into some register of quantum states (say using binary encoding into qubits). Then applying $U_p$ to a superposition of inputs is easy and I can easily construct a circuit that prepares the state $$\frac{1}{\sqrt{n}}\sum_{x=1}^n |x\rangle |p(x)\rangle.$$ My question is the following, using what I have described above or otherwise how could I prepare the quantum state $$|p\rangle:=\sum_{x=1}^n \sqrt{p(x)}|x\rangle$$ given access to $U_p$.
Remarks: My question could be seen as how one can make this fit into the amplitude amplification scheme.
One can see that this is a generalization of the typical quantum search, since if $p(x)=\delta_{x,y}$ (the distribution that is $1$ if $x=y$ and 0 if $x\neq y$) then $U_p$ is the quantum black-box for one marked item quantum search, and therefore preparing the state $|y\rangle$ can be done with $\Theta(\sqrt{n})$ queries to $U_{\delta(x,y)}$.
Update: I think this might boil down to someone explaining how I might implement the relative-phase like transformation $$ V:|x\rangle|f(x)\rangle\mapsto |x\rangle \big(\sqrt{\tfrac{f(x)}{2^m}}|0\rangle+\sqrt{1-\tfrac{f(x)}{2^m}}|1\rangle\big)$$ using some sort of controlled rotation?