hiho week 39 register

Ended

Participants:2159

Verdict:Accepted
Score:100 / 100
Submitted:2015-04-03 01:36:27

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#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;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX