求助orz 不知道为啥TLE了四分之三的点

P1908 逆序对

GGAD @ 2019-10-05 19:06:42

#include<bits/stdc++.h>
using namespace std;
int n;
long long sum;
int a[500010];
int biu[500010];
void s(int x,int y) {
    if(x==y) return;
    int m=(x+y)/2;
    s(x,m);
    s(m+1,y);
    int i=x,j=m+1,rua=x;
    while(i<=m&&j<=y) {
        if(a[i]<=a[j]) biu[rua++]=a[i++];
        else biu[rua++]=a[j++],sum+=(long long)(m-i+1);
    }
    while(i<=m) biu[rua++]=a[i++];
    while(j<=y) biu[rua++]=a[j++];
    for(int k=1; k<=y; ++k) a[k]=biu[k];
}
int main() {
    scanf("%d",&n);
    for(int i=1; i<=n; ++i) scanf("%d",&a[i]);
    s(1,n);
    printf("%lld",sum);
    return 0;
}

by GGAD @ 2019-10-06 13:35:33

@wangmaohua20090908 好的谢谢dalaoThanks♪(・ω・)ノ


上一页 |