Pagini recente » Cod sursa (job #2543118) | Cod sursa (job #3248929) | Cod sursa (job #737342) | Cod sursa (job #2520573) | Cod sursa (job #2908421)
///mereu va fi al catalea zice din pozitiile ramase(incepem de la final)
#include <fstream>
#define lsb(x) x & (-x)
#pragma optimize GCC ("Ofast")
using namespace std;
class InParser {
private:
FILE *fin;
char *buff;
int sp;
char read_ch() {
++sp;
if (sp == 4096) {
sp = 0;
fread(buff, 1, 4096, fin);
}
return buff[sp];
}
public:
InParser(const char* nume) {
fin = fopen(nume, "r");
buff = new char[4096]();
sp = 4095;
}
InParser& operator >> (int &n) {
char c;
while (!isdigit(c = read_ch()) && c != '-');
int sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
InParser& operator >> (long long &n) {
char c;
n = 0;
while (!isdigit(c = read_ch()) && c != '-');
long long sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
};
InParser cin ("schi.in");
ofstream cout ("schi.out");
const int N = 3e4;
int aib[N + 2], v[N + 2], sol[N + 2];
int n;
void update (int pos, int val)
{
for (int i = pos; i <= n; i += lsb(i))
aib[i] += val;
}
int query(int pos)
{
int sum = 0;
for (int i = pos; i >= 1; i -= lsb(i))
sum += aib[i];
return sum;
}
int cb (int st, int dr, int val)
{
int med, last = -1;
while (st <= dr)
{
med = (st + dr) >> 1;
if (med - query(med) >= val)
{
last = med;
dr = med - 1;
}
else
st = med + 1;
}
return last;
}
int main()
{
cin >> n;
ios_base :: sync_with_stdio(false);
for (int i = 1; i <= n; ++i)
{
cin >> v[i];
}
sol[v[n]] = n;
update (v[n], 1);
for (int i = n - 1; i >= 1; --i)
{
int pos = cb(1, n, v[i]);
update (pos, 1);
sol[pos] = i;
}
for (int i = 1; i <= n; ++i)
cout << sol[i] << '\n';
return 0;
}