P14220 [GeeksforGeeks] Count pairs in an array4145
普及-
题目描述

Given an array of integers arr[0..n-1], count all pairs (arr[i], arr[j]) in it such that iarr[i] > jarr[j],
and 0 ≤ i < j < n.

Example 1:
Input :
arr[] = {5, 0, 10, 2, 4, 1, 6}
Output :
5
Explanation :
Pairs which hold condition iarr[i] > jarr[j] are
(10, 2) (10, 4) (10, 1) (2, 1) (4, 1)

Example 2:
Input :
arr[] = {8, 4, 2, 1}
Output :
2

Your Task:
You don't need to read input or print anything. Your task is to complete the function countPairs() which takes the array A[] and its size N as inputs and returns the required result.

Expected Time Complexity: O(N. log(N))
Expected Auxiliary Space: O(N. log(N))

Constraints:
1 ≤ N ≤ 10^{5}
1 ≤ A[ ] ≤ 10^{3}

输入格式

见题面

输出格式

见题面

样例输入
arr[] = {5, 0, 10, 2, 4, 1, 6}
样例输出
5