No result for C++ Merge Sort

The code compiled successfully and I am not getting the expected result. I picked up some sections that I think might have problems.

I have updated the full version of merge function,thanks.

long merge(vector<int> l,vector<int> r,vector<int> a){

int lengthL = l.size();
int lengthR = r.size();

long count = 0;

int i = 0;
int j = 0;
int k = 0;

while(i < lengthL && j < lengthR)
{
    if(l[i] <= r[j])
    {
        a[k] = l[i];
        i += 1;
    }
    else
    {
        a[k] = r[j];
        j += 1;
        count += lengthL-i;

    }

    k += 1;
}

while(i<lengthL)
{
    a[k] = l[i];
    i = i + 1;
    k = k + 1;
}
 while(j<lengthR)
{
    a[k] = r[j];
    j = j + 1;
    k = k + 1;
}

return count;

}

MergeSort part, or shouldn't I use vector in here?

long countInversions(vector<int> arr) {
    long count = 0;
    int n = arr.size();

    if(n>=2)
    {
        int mid = n/2;
        vector<int> lArray(mid);
        vector<int> rArray(n-mid);

        for(int i = 0; i < mid; i++)
            lArray.push_back(arr[i]);

        for(int j = mid; j < n; j++)
            rArray.push_back(arr[j]);

        count += countInversions(lArray);
        count += countInversions(rArray);

        count += merge(lArray,rArray,arr);
    }

    return count;

}

main function I even tried to use array to solve the problem, but also crashed.

int main(){
       ...
        cout << countInversions(arr) << endl;
    }
    return 0;

}