为什么错了,蒟蒻求教

P1908 逆序对

帅皮的瓜粉 @ 2020-03-16 16:28:21

代码

#include<bits/stdc++.h>
using namespace std;
int a[1000000],tmp[1000000];
long long s=0;
void mergeArray(int l,int r,int mid)
{
    int i=l,j=mid+1;
    int n=mid,m=r;
    int x=0;
    while(i<=n&&j<=m)
    {
        if(a[i]<=a[j])
        {
            tmp[x++]=a[i++];
        }
        else 
        {
            tmp[x++]=a[j++];
            s+=mid-i+1;
        }
    }
    while(i<=n)
    {
        tmp[x++]=a[i++];
    }
    while(j<=n)
    {
        tmp[x++]=a[j++];
    }
    for(int i=0;i<x;i++)
    {
        a[l+i]=tmp[i];
    }
            }
void mergeSort(int l,int r)
{
    if(l<r)
    {
        int mid=(r+l)/2;
        mergeSort(l,mid);
        mergeSort(mid+1,r);
        mergeArray(l,r,mid);
    }
}

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    mergeSort(0,n-1);
    printf("%d ",s);
    return 0;
}

luogu.com.cn/record/31816508


by infinities @ 2020-03-16 16:32:13

问题是您怎么错了,TLE还是RE还是WA还是...


by 帅皮的瓜粉 @ 2020-03-16 16:33:37

@装弱是种美德 是WA


by 帅皮的瓜粉 @ 2020-03-16 16:33:58

注:评测结果在最下面


by 帅皮的瓜粉 @ 2020-03-16 16:35:15

@装弱是种美德 巨佬,您可以答题了(逃)


by 帅皮的瓜粉 @ 2020-03-16 16:36:34

@装弱是种美德 。。。


by 帅皮的瓜粉 @ 2020-03-16 16:37:14

@装弱是种美德 您太巨了


by liqingyang @ 2020-03-16 16:38:09

@谢哥二号 i<=mid&&j<=r


by 帅皮的瓜粉 @ 2020-03-16 16:38:32

@liqingyang Where?


by 帅皮的瓜粉 @ 2020-03-16 16:40:06

https://www.luogu.com.cn/record/31817032


by liqingyang @ 2020-03-16 16:41:51

@XCGL 还有应该是printf("%lld",s);


| 下一页