• P5463 小鱼比可爱(加强版)


    ________________________________________________________________________________________________________

    虽然推出来了规律但没有想到乘法分配律

    好好研究一下离散化

    ————————————————————————

    #include<bits/stdc++.h>
    using namespace std;
    int b[1000010],n,m,c[1000010],f[1000010];
    void add(int x,int y){for(;x<=m;x+=x&(-x))f[x]+=y;}
    int sum(int x)
    {
        int ans=0;
        for(;x;x-=x&(-x))ans+=f[x];
        return ans;
    }
    int main()
    {
        cin>>n;
        for(int i=1;i<=n;i++){cin>>b[i];c[i]=b[i];}
        sort(b+1,b+n+1);
        m=unique(b+1,b+1+n)-b-1;
        for(int i=1;i<=n;i++)c[i]=lower_bound(b+1,b+m+1,c[i])-b;
        long long ans=0;
        for(int i=1;i<=n;i++)
        {
            add(c[i],i);
            ans+=(n-i+1)*(sum(m)-sum(c[i]));
        }
        cout<<ans;
     } 
  • 相关阅读:
    hlgoj 1766 Cubing
    Reverse Linked List
    String to Integer
    Bitwise AND of Numbers Range
    Best Time to Buy and Sell Stock III
    First Missing Positive
    Permutation Sequence
    Next Permutation
    Gray Code
    Number of Islands
  • 原文地址:https://www.cnblogs.com/SFWR-YOU/p/11197932.html
Copyright © 2020-2023  润新知