Pagini recente » Cod sursa (job #1996000) | Cod sursa (job #2374685) | Cod sursa (job #3288689) | Cod sursa (job #179222) | Cod sursa (job #3209677)
#include <iostream>
#include <fstream>
using namespace std;
int vect[100001], n, v[100001], sol[100001];
int query(int p)
{
int sum = 0;
for (int i = p; i; i -= i & -i)
sum += vect[i];
return sum;
}
int bs(int p)
{
int s = 1, d = n, poz = n;
while (s <= d)
{
int m = (s + d) >> 1;
if (query(m) >= p)
{
d = m - 1;
poz = m;
}
else s = m + 1;
}
return poz;
}
void update(int p, int x)
{
for (int i = p; i <= n; i += i & -i)
vect[i] += x;
}
int main()
{
ifstream fin("schi.in");
ofstream fout("schi.out");
int i;
fin >> n;
for (i = 1; i <= n; ++i)
{
fin >> v[i];
update(i, 1);
}
for (i = n; i >= 1; --i)
{
int p = bs(v[i]);
update(p, -1);
sol[p] = i;
}
for (i = 1; i <= n; ++i)
fout << sol[i] << '\n';
return 0;
}