summaryrefslogtreecommitdiff
path: root/content/math/permIndex.cpp
blob: 563b33adf8a1dfe10a09410775534e4fa004be3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
ll permIndex(vector<ll> v) {
	Tree<ll> t;
	ranges::reverse(v);
	for (ll& x : v) {
		t.insert(x);
		x = t.order_of_key(x);
	}
	ll res = 0;
	for (int i = ssize(v); i > 0; i--) {
		res = res * i + v[i - 1];
	}
	return res;
}