#include<iostream>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> Node;
int main()
{
int n;
cin>>n;
Node s;
long long ans=0;
while(n--)
{
int x;
cin>>x;
ans+=s.order_of_key(x);
s.insert(x);
}
cout<<ans;
return 0;
}
用平衡二叉搜索树。
AC纪录