________________________________________________________________________________________________________
虽然推出来了规律但没有想到乘法分配律
好好研究一下离散化
————————————————————————
#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; }