No.
Your output for the first case should be 22. Also this is not how you check the efficiency of your code. You should try to check in some competitive programming sites for similar kind of problems. For example there a problem in spoj for Counting inversion. Here is the link:
http://www.spoj.com/problems/INVCNT/
Try submitting it there.