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