Problem list
Log in
#r03223 · Online Judge > GoldOJ

Swap Array Elements

Bronze III 2.0 s 256 MB

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
Source
Online Judge > GoldOJ
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code