Skip to content

Instantly share code, notes, and snippets.

@rikuTanide
Last active January 20, 2020 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rikuTanide/6ec3bf87e19bd39ae1ab4e2bc019e5a9 to your computer and use it in GitHub Desktop.
Save rikuTanide/6ec3bf87e19bd39ae1ab4e2bc019e5a9 to your computer and use it in GitHub Desktop.
i番目の要素がソートした時に何番目か記憶しておいてくれるもの
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