归并排序TLE后7个点

P1774 最接近神的人

```cpp #include<iostream> using namespace std; #include<cstdio> #define MAXN 500010 int a[MAXN],b[MAXN],n; long long ans=0; void gbsort(int l,int r) { if(l>=r) return; int mid=(l+r)/2; gbsort(l,mid); gbsort(mid+1,r); int L=l,R=mid+1; int cnt=l; while(L<=mid && R<=r) { while(a[L]<=a[R] && L<=mid) { b[cnt]=a[L]; cnt++; L++; } while(a[L]>a[R] && R<=r) { b[cnt]=a[R]; cnt++; R++; ans+=(mid-L+1); } } for(L;L<=mid;L++) b[cnt++]=a[L]; for(R;R<=r;R++) b[cnt++]=a[R]; for(int i=1;i<=r;i++) a[i]=b[i]; } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); gbsort(1,n); printf("%lld\n",ans); return 0; } ```
by 3_Meow @ 2018-09-08 14:41:33


@[dhfhwidb](/space/show?uid=84638) 直接把逆序对的代码粘来就好了
by tocek_shiki @ 2018-09-08 14:47:00


@[fff团666](/space/show?uid=49562) 只是不明白为什么会T,是归并里面打错了吗qaq
by 3_Meow @ 2018-09-08 15:52:11


这就是逆序对的题,比较简单。
by 反手for循环 @ 2019-05-25 20:02:17


37分,你是三哈哈
by 李夹木 @ 2021-08-18 20:04:49


|