Priori_Incantatem @ 2019-04-05 09:13:38
我的评测记录
i,j,k
用作数组下标类型无效?
代码:
#include<iostream>
#include<cstdio>
using namespace std;
const int N=2505;
int a[N],r[N],n;
long long ans;
void merge_sort(int l,int r)
{
if(l==r)return;
int mid=(l+r)/2;
merge_sort(l,mid);
merge_sort(mid+1,r);
int i=l,j=mid+1,k=l;
while(i<=mid&&j<=r)
{
if(a[i]<=a[j])r[k++]=a[i++];
else r[k++]=a[j++],ans+=(long long)mid-i+1;
}
while(i<=mid)r[k]=a[i],i++,k++;
while(j<=r)r[k]=a[j],k++,j++;
for(int i=l;i<=r;++i)a[i]=r[i];
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
merge_sort(1,n);
printf("%lld\n",ans);
return 0;
}
by Simples @ 2019-04-05 09:20:43
少年,来学BIT吧。。。
by Kubic @ 2019-04-05 09:26:32
@_Wolverine 这个CE得太骚了我看不出来
by pjykk @ 2019-04-05 09:35:52
for(int i=l;i<=r;++i)a[i]=r[i];
估计是这一行吧QwQ
by agicy @ 2019-04-05 09:37:11
@_Wolverine
数组r
与右端点r
重复了,把数组名改一下。
by Limit @ 2019-04-05 09:38:08
两个r是个蛇
by Priori_Incantatem @ 2019-04-05 10:02:37
@卢安来 QwQ
by Priori_Incantatem @ 2019-04-05 10:14:13
AC了
谢谢各位