The following solution is accepted as correct solution in the practice link of the question , But when i submitted the same Code during the contest with int inv=0; statement declared outside the while loop it was not accepted , Why??
When you are putting the statement inv=0 , outside the loop , it is not initialised everytime , so it will keep on adding everytime and give wrong answer . For example if for 1st query answer is 1 for second answer is also 1 , if you donot initialise it to zero for the second time , it will give 2 as answer which is wrong . Hope it helps .
1 Like
@the65bit is right… but one more thing inv will be long long not int… i got WA in 2 cases because of that…