long sort_count(long A[], long B[], long i,long j){
 long q;
 if(i >=j ) return 0;
 else{
  q = (i+j)/2;
  return sort_count(A, B, i, q) +
      sort_count(A, B, q+1, j)+
      merge_count(A, B, i, q, j);
 }
 
}
Beispiel #2
0
long long int merge_count(vector<int> &A){
    int n = A.size();
    if(n <= 1)
        return 0;

    vector<int> L(A.begin(), A.begin()+n/2);
    vector<int> R(A.begin()+n/2, A.end());

    long long int cnt = merge_count(L) + merge_count(R);

    L.push_back(INF); R.push_back(INF);
    int li = 0, ri = 0, ai = 0;
    while(ai<n){
        if(L[li] <= R[ri]){
            A[ai++] = L[li++];
        }else{
            cnt += L.size()-1 - li;
            A[ai++] = R[ri++];
        }
    }
    return cnt;
}
Beispiel #3
0
static void merge_all (struct sf *sf, int type, uint64_t *inout, uint64_t *in)
{
    struct str *strings = (struct str *)sf->base;
    
    int nStatTypes = atoi((const char *)&strings[2]);
    
    int desc = atoi((const char *)&strings[(5+(type*2))]);
    int nCount = atoi((const char *)&strings[desc]);
    int nTally = atoi((const char *)&strings[desc+1]);
    int nBin = atoi((const char *)&strings[desc+2]);
    int nAttr = nStatTypes >= 4 ? atoi((const char *)&strings[desc+3]) : 0;
    int i;
    
    desc += nStatTypes;
    
    for ( i = 0 ; i < nAttr ; i++ ) {
	int offset = i+nCount+(nTally*3)+(nBin*35);
	merge_attr(&inout[offset],&in[offset]);
    }
    
    
    for ( i = 0 ; i < nCount ; i++ ) {
	int offset = i;
	merge_count(&inout[offset],&in[offset]);
    }
    
    for ( i = 0 ; i < nTally ; i++ ) {
	int offset = (i*3)+nCount;
	merge_tally(&inout[offset],&in[offset]);
    }
    
    for ( i = 0 ; i < nBin ; i++ ) {
	int offset = (i*35)+nCount+(nTally*3);
	merge_bin(&inout[offset],&in[offset]);
    }
}