"I hereby challenge you, Ponyvillians: anything you can do, I can do better. Any takers? Anyone? Or is Trixie destined to be the greatest equine who has ever lived!?!" — "Boast Busters"
Given two permutation P
0 && P
1 of {0, 1, ..., n - 1}, we define the crossing number of it as follows. Write P
0 from left to right above P
1 and draw a straight line between each same elements. The crossing number of P
0 and P
1 is the number of pairs of lines that cross.
For example, if n = 5, and P
0 = {0, 1, 2, 3, 4}, and P
1 = {1, 3, 0, 2, 4}, then the crossing number of P
0 and P
1 is 3, as shown in the figure below.
Now given you the two permutation, you need to implement the following operations:
SWAP p a b: swap P
p[a] and P
p[b] (0<=p<=1, 0<=a, b<=n-1).
QUERY: ask the crossing number of the current P
0 and P
1.