-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathschi.cpp
51 lines (46 loc) · 1.04 KB
/
schi.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# include <fstream>
# include <algorithm>
# define NR 30005
using namespace std;
ifstream f("schi.in");
ofstream g("schi.out");
int i,j,n,LOC;
int poz[NR], loc[NR], ARB[4*NR];
void init (int nod, int ci, int cs)
{
if (ci==cs) ARB[nod]=1;
else {
int mij=(ci+cs)/2;
if (ci<=mij) init (2*nod, ci, mij);
if (cs>mij) init (2*nod+1, mij+1, cs);
ARB[nod]=ARB[2*nod]+ARB[2*nod+1];
}
}
void cauta (int nod, int ci, int cs, int ord)
{
if (ci==cs)
{
LOC=ci; --ARB[nod];
}
else {
int mij=(ci+cs)/2;
if (ord<=ARB[2*nod]) cauta (2*nod, ci, mij, ord);
else cauta (2*nod+1, mij+1, cs, ord-ARB[2*nod]);
--ARB[nod];
}
}
int main ()
{
f>>n;
for (i=1; i<=n; ++i)
f>>loc[i];
init (1, 1, n);
for (i=n; i>=1; --i)
{
cauta(1, 1, n, loc[i]);
poz[LOC]=i;
}
for (i=1; i<=n; ++i)
g<<poz[i]<<"\n";
return 0;
}