Created
October 4, 2018 14:47
-
-
Save htfy96/0d1e9afcf6f0305fa0eea1d2addc71d5 to your computer and use it in GitHub Desktop.
discrete
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
#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