Cod sursa(job #3296639)

Utilizator biancalautaruBianca Lautaru biancalautaru Data 14 mai 2025 22:41:41
Problema Schi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <fstream>
#define DIM 30001
using namespace std;
ifstream fin("schi.in");
ofstream fout("schi.out");
int n, c[DIM], v[DIM], a[4 * DIM];

void build(int st, int dr, int nod) {
	if (st == dr)
		a[nod] = 1;
	else {
		int mid = (st + dr) / 2;
		build(st, mid, 2 * nod);
		build(mid + 1, dr, 2 * nod + 1);
		a[nod] = a[2 * nod] + a[2 * nod + 1];
	}
}

void update(int st, int dr, int nod, int f, int p) {
	if (st == dr) {
		a[nod] = 0;
		v[st] = f;
	}
	else {
		int mid = (st + dr) / 2;
		if (a[2 * nod] >= p)
			update(st, mid, 2 * nod, f, p);
		else
			update(mid + 1, dr, 2 * nod + 1, f, p - a[2 * nod]);
		a[nod] = a[2 * nod] + a[2 * nod + 1];
	}
}

int main() {
	fin >> n;
	for (int i = 1; i <= n; i++)
		fin >> c[i];
	build(1, n, 1);
	for (int i = n; i >= 1; i--)
		update(1, n, 1, i, c[i]);
	for (int i = 1; i <= n; i++)
		fout << v[i] << "\n";
	return 0;
}