Cod sursa(job #2635037)

Utilizator alex.prohnitchiAlex Prohnitchi alex.prohnitchi Data 13 iulie 2020 00:45:12
Problema Schi Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.24 kb
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

typedef long long ll;

const ll mod=1e9+7;

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int nmax=1e7+5;

#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define rc(x)  return cout<<x<<"\n",0
#define sz(s)  (int) s.size()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;

ll t[nmax*4];
int a[nmax],b[nmax];

ifstream f("schi.in");
ofstream g("schi.out");

void build(int v, int tl, int tr) {
	if (tl==tr) {
		t[v]=1;
	}
	else {
		int tm=(tl+tr)/2;
		build(2*v,tl,tm);
		build(2*v+1,tm+1,tr);
		t[v]=t[2*v]+t[2*v+1];
	}
}

void update(int v, int tl, int tr, int val, int pos) {
	if (tl==tr) {
		t[v]=0;
		b[tl]=val;	
		return;
	}
	else {
		int tm=(tl+tr)/2;
		if (pos<=t[2*v]) {
			update(2*v,tl,tm,val,pos);
		}
		else {
			update(2*v+1,tm+1,tr,val,pos-t[2*v]);
		}
		t[v]=t[2*v]+t[2*v+1];
	}
}

int main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	f >> n;
	build(1,1,n);
	for (int i=1; i<=n; i++) {
		f >> a[i];
	}
	for (int i=n; i>=1; i--) {
		update(1,1,n,i,a[i]);
	}
	for (int i=1; i<=n; i++) {
		g << b[i] << '\n';
	}
}