hiho week 39 register

Ended

Participants:2159

Verdict:Accepted
Score:100 / 100
Submitted:2015-03-31 09:07: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;
class Solution {
public:
    long long reverseCount; 
public:
    Solution(){
        reverseCount =0;
    }
    int * divConSort(int *ivec, int n) {
        if(n<=1) {int *tp = new int(ivec[0]);return tp;}
        int i=0;
        int j=0;
        int * ip =divConSort(ivec,n/2);
        int * jp =divConSort(ivec+n/2,n-n/2);
        int *tp = new int[n];
        while(i<n/2 && j<n-n/2){
            if(*ip>*jp){
                *tp++ = *jp++;
                ++j;
                reverseCount += (n/2-i);
            }
            else{
                *tp++ = *ip++;
                ++i;
            }
        }
        if(i == n/2)
            while(j<n-n/2) {*tp++ = *jp++;++j;}
        else if(j==n-n/2)
            while(i<n/2) {*tp++ = *ip++; ++i;}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX