Pagini recente » Cod sursa (job #1871325) | Cod sursa (job #2448169) | Cod sursa (job #2135476) | Rating Daciana-Adela (Daciana17) | Cod sursa (job #1155727)
#include <fstream>
using namespace std;
ifstream fin ("schi.in");
ofstream fout ("schi.out");
int v[30005],w[4*30001],a[30005],n,i,loc;
void update (int nod, int st, int dr ) {
if (st==dr) {
w[nod]=1;
return;
}
int mid = (st+dr)/2;
if (i<=mid)
update (2*nod,st,mid);
else
update (2*nod+1,mid+1,dr);
w[nod]=w[2*nod]+w[2*nod+1];
}
void update2 (int nod, int st, int dr, int x) {
if (st==dr) {
w[nod]=0;
loc=st;
return;
}
int mid =(st+dr)/2;
if (x<=w[2*nod])
update2 (2*nod, st, mid, x);
else
update2 (2*nod+1, mid+1, dr, x-w[2*nod]);
w[nod]=w[2*nod]+w[2*nod+1];
}
int main () {
fin>>n;
for (i=1;i<=n;i++)
fin>>v[i];
for (i=1;i<=n;i++)
update (1,1,n);
for (i=n;i>=1;i--) {
update2 (1,1,n,v[i]);
a[loc]=i;
}
for (i=1;i<=n;i++)
fout<<a[i]<<"\n";
return 0;
}