秦冇甪饕 @ 2022-06-20 19:14:59
难道我是数据开得不够大?
#include <bits/stdc++.h>
using namespace std;
int a[1000]={},temp[1000]={},sum=0;
void msort(int l,int r)
{
if(l>=r) return;
int mid=(l+r)/2;
msort(l,mid);
msort(mid+1,r);
int i=l,j=mid+1,k=l;
while(i<=mid&&j<=r)
{
if(a[i]<a[j]) temp[k++]=a[i++];
else
{
temp[k++]=a[j++];
sum+=(mid-i+1);
}
}
while(i<=mid) temp[k++]=a[i++];
while(j<=r) temp[k++]=a[j++];
for(int o=l;o<=r;o++) a[o]=temp[o];
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
msort(1,n);
cout<<sum;
return 0;
}
我也没检查出什么问题...
by MujicaSaki @ 2022-06-20 19:15:56
@秦冇甪饕 正确的
by MujicaSaki @ 2022-06-20 19:16:13
@秦冇甪饕 数组开小了
by _DeadPig_ @ 2022-06-20 19:18:27
对于所有数据,
by Y2y7m @ 2022-06-20 19:19:57
@秦冇甪饕 做题不看数据那你会觉得你能AKNOI
by Y2y7m @ 2022-06-20 19:21:47
@秦冇甪饕 long long 没开!
by 秦冇甪饕 @ 2022-06-20 19:24:06
谢谢啊!虽然口气比较强硬...
by 秦冇甪饕 @ 2022-06-20 19:25:07
#include <bits/stdc++.h>
using namespace std;
long long a[500003]={},temp[500003]={},sum=0;
void msort(long long l,long long r)
{
if(l>=r) return;
long long mid=(l+r)/2;
msort(l,mid);
msort(mid+1,r);
long long i=l,j=mid+1,k=l;
while(i<=mid&&j<=r)
{
if(a[i]<a[j]) temp[k++]=a[i++];
else
{
temp[k++]=a[j++];
sum+=(mid-i+1);
}
}
while(i<=mid) temp[k++]=a[i++];
while(j<=r) temp[k++]=a[j++];
for(long long o=l;o<=r;o++) a[o]=temp[o];
}
int main()
{
long long n;
cin>>n;
for(long long i=1;i<=n;i++)
{
cin>>a[i];
}
msort(1,n);
cout<<sum;
return 0;
}
这样?