Pagini recente » Cod sursa (job #374358) | Cod sursa (job #284867) | Cod sursa (job #664174) | Cod sursa (job #3152644) | Cod sursa (job #2702365)
#include <fstream>
#define mF "schi"
std::ifstream in(mF ".in");
std::ofstream out(mF ".out");
const int N = 30777;
int n, i, I[N], V[N], R[N];
int S(int i) {int s = 0; do s += V[i]; while (i ^= i & -i); return s;}
int Q(int s) {int i = 1, j = n, m; while (i <= j) if (S(m = i+j>>1) < s) i = m+1; else j = m-1; return i;}
void U(int i) {do V[i]--; while (i += i & -i, i <= n);}
int main()
{
in >> n;
for (i = 1; i <= n; i++) in >> I[i], V[i + (i & -i)] += ++V[i];
for (i = n; i; i--) {int p = Q(I[i]); R[p] = i; U(p);}
for (i = 1; i <= n; i++) out << R[i] << '\n';
}