Lang:G++
Edit12345678910111213141516171819202122232425262728293031#include <iostream>using namespace std;long merge(long arr[],long temp[],int left,int mid,int right){int i=left,j=mid,k=left;long count=0;while((i<=mid-1)&&(j<=right)){if(arr[i]<=arr[j]){temp[k++]=arr[i++];}else{temp[k++]=arr[j++];count+=mid-i;}}while(i<=mid-1){temp[k++]=arr[i++];}while(j<=right){temp[k++]=arr[j++];}for(i=left;i<=right;i++){arr[i]=temp[i];}return count;}long sortandcount(long arr[],long temp[],int left,int right){long count=0;int mid;if(right>left){mid=(right+left)/2;