blob: 9e47f9bd76331f35e5e19eaa95517cd6b4e544c7 (
plain)
1
2
3
4
5
6
7
8
9
|
ll inversions(const vector<ll>& v) {
Tree<pair<ll, ll>> t; //ordered statistics tree @\sourceref{datastructures/pbds.cpp}@
ll res = 0;
for (ll i = 0; i < sz(v); i++) {
res += i - t.order_of_key({v[i], i});
t.insert({v[i], i});
}
return res;
}
|