@suryanit He used that fact that any swap operation will simply alter the parity of the no. of inversions. We can write a simple O(n) procedure to count the number of swaps required to sort the given permutation of 1-N, and then use this number to easily determine the final parity. The main insight here is that the no of inversions depends solely on the final order of elements, and not on the swaps which are used to get there.
I actually already did O((N + Q)logn * log(max)) using segtree on trie or treap on trie but both gave TLE , idk why but O(NlogN + NrootNlogMax) worked faster.