#P7343. 【DSOI 2021】电子跃迁
【DSOI 2021】电子跃迁
Description
In your view, there is a row of electrons, each with different energy. What you need to do is sort this row of electrons by swapping adjacent electrons. Sorted means: place the electron with the smallest energy on the far left, closest to the nucleus; place the second smallest in the second position; ...; and place the electron with the largest energy on the far right.
However, you find that strange forces suddenly appear between the orbitals, making the electron at position unable to be swapped with the electron at position .
You strongly believe that this force will overturn current physical theories. What you need to do is make the current row of electrons as sorted as possible in order to discover the pattern.
As sorted as possible means: under the constraints, move the electron with the smallest energy as far left as possible until a barrier appears, and so on.
Input Format
The first line contains two integers , representing the number of electrons and the number of forces.
The second line contains integers describing the initial arrangement of electrons, where the -th number represents the energy of the -th electron.
The third line contains integers. The -th integer indicates that the electron at position cannot be swapped with the electron at position .
Output Format
Output one line with integers, representing the arrangement that is as sorted as possible under these conditions.
3 0
3 2 1
1 2 3
7 2
1 3 1 4 5 2 1
2 4
1 3 1 4 1 2 5
Hint
For of the testdata, .
For another of the testdata, .
For of the testdata, $0 \le n, m \le 5 \times 10^5, 1 \le x_i \le n - 1, 1 \le a_i \le 10^9$.
Translated by ChatGPT 5
京公网安备 11011102002149号