题面链接:http://acm.hdu.edu.cn/showproblem.php?pid=6318
类型:逆序对
题解:相同了 一次交换=一次逆序 就结束了
答案 ans=逆序数*min(x,y)
(逆序数套的是网上的板子)
C++
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 100003
using namespace std;
int a[N],tmp[N],n,x,y;
long long ans;
void gsort(int l,int r)
{
if(l==r)
return ;
int mid=(l+r)/2;
gsort(l,mid),gsort(mid+1,r);
int i=l,j=mid+1,k=l;
while(i<=mid&&j<=r)
{
if(a[i]<=a[j])
tmp[k++]=a[i++];
else
{
ans+=mid-i+1;
tmp[k++]=a[j++];
}
}
while(i<=mid)
tmp[k++]=a[i++];
while(j<=r)
tmp[k++]=a[j++];
for(int i=l; i<=r; i++)
a[i]=tmp[i];
}
int main()
{
std::ios::sync_with_stdio(false);
while(cin>>n>>x>>y)
{
x=x<y?x:y;
for(int i=1; i<=n; i++)
cin>>a[i];
gsort(1,n);
ans=ans*x;
cout<<ans<<endl;
ans=0;
}
return 0;
}