An array of $N$ integers is given, then $M$ swap operations, each a pair of 1-based positions $i$ $j$ whose values are exchanged (applied in order). Print the final array.
Input
Line 1: $N$ $M$. Line 2: $N$ integers. Next $M$ lines: i j.
Output
Print the array after all swaps.
Example 1
Input
5 3 10 20 30 40 50 1 3 4 2 3 5
Output
30 40 50 20 10
Discussion
Threads about this problem. Spoilers are collapsed; wrap hints in
||double bars||.No discussion yet. Start a thread if something here needs explaining.