后面十个点WA 大佬帮忙看看 谢谢

P1908 逆序对

DOs__lx @ 2020-02-23 13:05:49

只有50分 QWQ

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define re register
const int M=5e5+5;
int a[M],r[M],n;
long long ans;
namespace fir{
    inline int read(){
        int s=0,w=1;
        char c=getchar();
        while(c>'9'||c<'0'){
            if(c=='-') w=-1;
            c=getchar();
        }
        while(c>='0'&&c<='9'){
            s=(s<<3)+(s<<1)+(c^48);
            c=getchar();
        }
        return s*w;
    }
    inline void write(int a){
        int tot=abs(a);
        if(a<0) putchar('-');
        int cnt=0;
        char c[M];
        while(tot>0){
            c[cnt++]=tot%10+'0';
            tot/=10;
        }
        while(cnt>0) putchar(c[--cnt]);
    }
}
namespace solve{
    inline void msort(int s,int t){
        if(s==t) return;
        int mid=s+t>>1;
        msort(s,mid);
        msort(mid+1,t);
        int i=s;
        int j=mid+1;
        int k=s;
        while(i<=mid&&j<=t){
            if(a[i]<=a[j]){
                r[k]=a[i];
                k++;
                i++;
            }
            else{
                r[k]=a[j];
                k++;
                j++;
                ans+=(long long)mid-i+1;
            }
        }
        while(i<=mid){
            r[k]=a[i];
            k++;
            i++;
        }
        while(j<=t){
            r[k]=a[j];
            k++;
            j++;
        }
        for(int i=s;i<=t;++i) a[i]=r[i];
    }
}
int main(){
    n=fir::read();
    for(int i=1;i<=n;++i) a[i]=fir::read();
    solve::msort(1,n);
    fir::write(ans);
    return 0;
} 

by 神山识 @ 2020-02-23 13:07:19

@DOs__lx 没开long long吧


by DOs__lx @ 2020-02-23 13:08:03

@我不是箭毒蛙 我改了试试


by Alarm5854 @ 2020-02-23 13:08:09

@DOs__lx 不开LL见祖宗!


by Alarm5854 @ 2020-02-23 13:08:44

等等,好像已经开了LL


by 神山识 @ 2020-02-23 13:09:21

@YCE3216037 肯定没开longlong,因为他输出的是负数


by 神山识 @ 2020-02-23 13:09:47

@DOs__lx #define int long long 试试看?


by Smile_Cindy @ 2020-02-23 13:11:27

@DOs__lx #define int long long试一试?


by DOs__lx @ 2020-02-23 13:12:20

@我不是箭毒蛙 main必须返回int吧,我康康


by Alarm5854 @ 2020-02-23 13:13:09

@DOs__lx signed main()即可


by 神山识 @ 2020-02-23 13:13:48

@DOs__lx signed main()很香的/wq


| 下一页