tletletle光了,神犇们救救蒟蒻⑧yyy

P1908 逆序对

森森鸭 @ 2019-08-18 13:44:52

用的归并,但是数据被巨佬加强了,过不了

话不多说直接上代码

#include <cstdio>
using namespace std;
int a[500010],ans=0;
void msort(int s,int t)
{
    int i,j,m=(s+t)/2,k,r[500010]={0};
    if(s==t) return;
    msort(s,m);
    msort(m+1,t);
    i=s;k=s;j=m+1;
    while(i<=m&&j<=t)
    {
        if(a[i]<a[j]) r[k]=a[i],i++,k++;
        else r[k]=a[j],j++,k++,ans+=m-i+1;
    }
    while(i<=m) r[k]=a[i],i++,k++;
    while(j<=t) r[k]=a[j],j++,k++;
    for(int i=s;i<=t;i++) a[i]=r[i];
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    msort(1,n);
    printf("%d",ans);
    return 0;
}

by _wkjzyc @ 2019-08-18 13:47:26

写树状数组鸭


by RenaMoe @ 2019-08-18 13:49:03

你试试把r数组开在全局


by RenaMoe @ 2019-08-18 13:49:58

或者加static


by comfort @ 2019-08-18 14:06:26

吸氧啊


by chenxia25 @ 2019-08-18 14:07:12

氧真好吸


by 紪絽 @ 2019-09-15 13:18:46

吸臭氧也可以


|