Cod sursa(job #2158135)

Utilizator AlexandruLuchianov1Alex Luchianov AlexandruLuchianov1 Data 10 martie 2018 10:52:28
Problema Schi Scor 75
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream in ("schi.in");
ofstream out ("schi.out");
int const nmax = 30000;
int const lgmax = 16;
int aib[5 + nmax];
int n;
void update(int x ,int val){
  while(x <= n){
    aib[x] += val;
    x += x ^ (x & (x - 1));
  }
}
int query[5 + nmax];
int sol[5 + nmax];

int main()
{
  in>>n;
  for(int i = 1 ; i <= n ;i++){
    in>>query[i];
    update(i , 1);
  }
  for(int i = n ; 0 < i ;i--){
    int result = 0;
    for(int j = lgmax ; 0 <= j ;j--){
      int jump = (1 << j);
      if(result + jump <= n){
        if(aib[result + jump] < query[i]){
          query[i] -= aib[result + jump];
          result += jump;
        }
      }
    }
    result++;
    update(result , -1);
    sol[result] = i;
  }
  for(int i = 1 ; i <= n ;i++)
    out<<sol[i]<<'\n';
  return 0;
}