找到逆序对的数量,然后乘以min(x,y);
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 100010;
ll n,x,y,ans;//ans记录逆序对的数量
ll tmp[maxn],a[maxn];
void merge(int l,int r,int m){
int i=l,j=m+1,k=l;
while(i<=m&&j<=r){
if(a[i]>a[j]){
tmp[k++]=a[j++];
ans+=m-i+1;
}
else{
tmp[k++]=a[i++];
}
}
while(i<=m)tmp[k++]=a[i++];
while(j<=r)tmp[k++]=a[j++];
for(int i=l;i<=r;i++) a[i]=tmp[i];
}
void merges(int l,int r){
if(l<r){
int m=(l+r)>>1;
merges(l,m);
merges(m+1,r);
merge(l,r,m);
}
}
int main()
{
ios::sync_with_stdio(false);
while(cin>>n>>x>>y){
for(int i = 0;i < n;i++)
scanf("%lld",&a[i]);
ans = 0;
merges(0,n-1);
printf("%lld\n",ans*min(x,y));
}
return 0;
}
#include<cstdio>
#include<iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
ll nxd;//逆序对的数量
void merges(ll *a,ll l,ll r)
{
if(l==r) return; //递归边界
ll c=l+(r-l)/2; //中值
merges(a,l,c);
merges(a,c+1,r);
ll t=r-l+1;
ll tt[t];
ll n=l;
ll m=c+1;
ll i=0;
while(n<=c||m<=r)
{
if(m>r||(n<=c&&a[n]<=a[m]))
{
tt[i++]=a[n++];
}
else
{
tt[i++]=a[m++];
nxd+=c-n+1;
}
}
n=l;
for(ll i=0;i<t;i++)
{
a[n++] = tt[i];
}
}
ll k[100010];
int main()
{
ll n,x,y;
while(~scanf("%lld%lld%lld",&n,&x,&y)){
nxd = 0;
for(int i = 0;i < n;i++) scanf("%lld",&k[i]);
merges(k,0,n-1);
ll s = nxd*min(x,y);
printf("%lld\n",s);
}
return 0;
}