Skip to content

Instantly share code, notes, and snippets.

@htfy96
Created October 4, 2018 14:47
Show Gist options
  • Save htfy96/0d1e9afcf6f0305fa0eea1d2addc71d5 to your computer and use it in GitHub Desktop.
Save htfy96/0d1e9afcf6f0305fa0eea1d2addc71d5 to your computer and use it in GitHub Desktop.
discrete
#include <bits/stdc++.h>
using namespace std;
int main()
{
vector<int> a {1, 3, 3, 2, 5};
vector<int> b;
for (int i=0; i<a.size(); ++i)
b.push_back(i);
sort(b.begin(), b.end(), [&](int i1, int i2) {
return a[i1] < a[i2];
});
int cnt = 0;
vector<int> newa; newa.resize(a.size());
for (int i=0; i<b.size(); ++i)
newa[b[i]] = i && a[b[i]] != a[b[i-1]] ? ++cnt : cnt;
for (int v: newa)
cout << v << " ";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment