zoukankan      html  css  js  c++  java
  • Swaps and Inversions HDU

    #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
    ", ans);
        }
    }
  • 相关阅读:
    hdu4726
    hdu2709
    hdu4706
    hdu4715
    快速幂取模
    快速幂
    asp.net中页面传值
    微信小程序支付
    sql 查询重复记录值取一条
    bower使用
  • 原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12288446.html
Copyright © 2011-2022 走看看