哪里错了啊

P1908 逆序对

夏义博 @ 2020-02-28 22:25:52

#include<bits/stdc++.h>
using namespace std;
int f(int a[],int l,int r,int t[]){
    int num=0;
    if(l-r<1){
        int m=(l+r)/2;
        num+=f(a,l,m,t);
        num+=f(a,m,r,t);
        int i=l,j=m,k=l;
        while(i<m&&j<r){
            if(a[i]>a[j]){num+=m-i;t[k++]=a[j++];}
            else t[k++]=a[i++];
        }
        while(i<l)t[k++]=a[i++];
        while(j<r)t[k++]=a[j++];
        for(int i=l;i<r;i++)a[i]=t[i];
    }
    return num;
} 
int main()
{
    int n,a[100],t[100],l,r;
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    cout<<f(a,l,r,t);
    return 0;
}

by Smile_Cindy @ 2020-02-28 22:29:41

@夏义博 废话你数组只有100,但是范围有500000


by 夏义博 @ 2020-02-28 22:33:35


by 夏义博 @ 2020-02-28 22:38:26

改了还是不对


|