summaryrefslogtreecommitdiff
path: root/math/permIndex.cpp
diff options
context:
space:
mode:
authormzuenni <michi.zuendorf@gmail.com>2022-06-27 17:19:28 +0200
committermzuenni <michi.zuendorf@gmail.com>2022-06-27 17:19:28 +0200
commit5ab8a5088b729a9953b8dff1b2a985dc8fb2098b (patch)
treeed40d6936c0e9eee40ba62751cbf99ecddbaddc2 /math/permIndex.cpp
parentadabbad9c51cf7cd3874bfde8eac1fbcf84fec10 (diff)
updated tcr
Diffstat (limited to 'math/permIndex.cpp')
-rw-r--r--math/permIndex.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/math/permIndex.cpp b/math/permIndex.cpp
new file mode 100644
index 0000000..09ff7f7
--- /dev/null
+++ b/math/permIndex.cpp
@@ -0,0 +1,14 @@
+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 (ll i = sz(v); i > 0; i--) {
+ res *= i;
+ res += v[i - 1];
+ }
+ return res;
+}