Weird thing with Inversion Count Problem

Hi! Yesterday, I posted this code to help finding out the bug. However, I managed to get the correct answer but a weird thing happened. I first did it (as mentioned in the code) without using an array temp to store the elements after merging, I got WA. But then, I used the array temp and it showed up correct answer. Why did that happen? I don’t think that the value of number of inversions seems to be anyhow depending on the array temp. We’re just storing the sorted values in temp and then copying them back to A. Can anybody provide an explanation?

Use ideone or pastebin for codes.

@sarsjits, done!