Last active
January 20, 2020 04:43
-
-
Save rikuTanide/6ec3bf87e19bd39ae1ab4e2bc019e5a9 to your computer and use it in GitHub Desktop.
i番目の要素がソートした時に何番目か記憶しておいてくれるもの
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Order { | |
vector<int> v; | |
vector<int> order; | |
public: | |
Order(vector<int> &v) : v(v), order(v.size()) { | |
vector<P> tmp(v.size()); | |
rep(i, v.size()) { | |
tmp[i].first = v[i]; | |
tmp[i].second = i; | |
} | |
sort(tmp.rbegin(), tmp.rend()); | |
rep(i, v.size()) { | |
order[tmp[i].second] = i; | |
} | |
} | |
int index(int i) { | |
return order[i]; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment