Google It.

5

2 votes
Problem

Two element of an array AA[i] and A[j] form an inversion if A[i]>A[j] and i<j.

You will be given the array A, you have to find sum of count of inversions for all subarrays.

INPUT:
First line contains a single integer N, which denotes the size of the array.
Second line contains N spaced integers denoting the elements of the array.

OUTPUT:
A single integer which is the desired answer modulo109+7.

CONSTRAINTS:
1N1051A[i]1018

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Inversion count for subarray [0,0] = 0
Inversion count for subarray [0,1] = 0
Inversion count for subarray [0,2] = 0
Inversion count for subarray [0,3] = 1
Inversion count for subarray [1,1] = 0
Inversion count for subarray [1,2] = 1
Inversion count for subarray [1,3] = 3
Inversion count for subarray [2,2] = 0
Inversion count for subarray [2,3] = 1
Inversion count for subarray [3,3] = 0

Sum of inversion count for all subarrays = 9 

 

Editor Image

?