蒟蒻求助,全RE了,求大佬指点

P1908 逆序对

徐浩宇 @ 2019-10-25 21:14:17

#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cmath>
using namespace std;
long int ans=9,a[100001],t[100001];
void merge(long int a[],int l,int r)
{
    if(l==r)return ;
    int mid=(l+r)/2;
    merge(a,l,mid);
    merge(a,mid+1,r);
    int i=l,j=mid+1,p=l;
    while(i<=mid&&j<=r)
    {
        if(a[i]>a[j])
        {
            t[p]=a[j];
            p++; j++;
            ans=mid-i+1+ans;
        }
        else 
        {
            t[p]=a[i];
            p++; i++;
        }
    }
    while(i<=mid)
    {
        t[p]=a[j];
        p++; i++;
    }
    while(j<=r)
    {
        t[p]=a[j];
        p++; i++;
    }
    for(i=l;i<=r;i++)
        a[i]=t[i];
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    merge(a,1,n);
    printf("%d",ans);
    return 0;
}

by 反手for循环 @ 2019-10-25 21:21:50

数组再开大点。。。


by 徐浩宇 @ 2019-11-08 23:52:10

@反手for循环 没用啊


|