Online Programming Server

Login

Login with facebook [?]

Facebook

Problem 1106: Inversions II

Problem ID 1106
Title Inversions II
pdf  
Description
Do you remember how bubble sort works? It swaps adjacent elements if they are not in the correct order. Given an array A, Alice is interested in how many swaps the bubble sort algorithm will perform.

This is equivalent to counting how many pairs of (i, j) satisfy i < j and A[i] > A[j], namely a inversion. The inversion number of an array is the number of inversions. Your task is compute this number.
Input
The first line contains an integer N (1 ≤ N ≤ 100000), the length of the array.
The second line contain N integers representing the array. (0 ≤ Ai ≤ 109)
Output
The inversion number of array A.
Sample Input
6
4 7 3 2 3 5
Sample Output
8
Hint
Merge Sort
Last Modified 2012-06-01 14:51:13
Time Limit 1 seconds
Memory Limit 64 MB
Accepted Solutions 0
Submitted Solutions 1
Difficulty Factor 276