Skip to content

Instantly share code, notes, and snippets.

@htfy96 htfy96/discrete.cpp
Created Oct 4, 2018

What would you like to do?
#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)
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
You can’t perform that action at this time.