标签:version turn cstring hdu col algorithm names 数组 pre
#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); } }
Swaps and Inversions HDU - 6318 树状数组+离散化
标签:version turn cstring hdu col algorithm names 数组 pre
原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12288446.html