#include<iostream> #include<algorithm> #include<cstring> #include<cstdio> using namespace std; typedef long long ll; const int N=1e5+10; int a[N]; int ra[N]; int tr[N]; int n,x,y; int sz; int lowbit(int x) { return x&-x; } void add(int x,int c) { for(int i=x;i<=n;i+=lowbit(i)) tr[i]+=c; } int sum(int x) { int res=0; for(int i=x;i;i-=lowbit(i)) res+=tr[i]; return res; } int main() { while(scanf("%d%d%d", &n, &x, &y) != EOF) { memset(tr,0,sizeof tr); for(int i=1;i<=n;i++) { scanf("%d", &a[i]); ra[i]=a[i]; } //离散化 sort(ra+1,ra+1+n); sz=unique(ra+1,ra+1+n)-ra-1; ll ans=0; for(int i=1;i<=n;i++) { int num=lower_bound(ra+1,ra+1+n,a[i])-ra; add(num,1); ans+=i-sum(num); } if(x<y) ans=ans*x; else ans=ans*y; printf("%lld\n", ans); } }
原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12288446.html
时间: 2024-10-11 00:08:55