Cod sursa(job #3152261)

Utilizator BossBobsterRobert Alexandru Costin BossBobster Data 24 septembrie 2023 14:48:28
Problema Schi Scor 100
Compilator cpp-32 Status done
Runda Arhiva de probleme Marime 2.89 kb
#include <iostream>
#include <string.h>
#include <random>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iomanip>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <array>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <valarray>
#include <memory>
#include <cassert>
#include <chrono>
#include <type_traits>
#include <stdexcept>
#include <string_view>
#include <regex>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<pis, string> piss;
typedef pair<int, short> pish;
typedef pair<string, string> pss;
typedef pair<int, char> pic;
typedef pair<pii, int> piii;
typedef pair<double, double> pdd;
typedef pair<double, int> pdi;
typedef pair<float, float> pff;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef unsigned short ushort;
typedef pair<uint, uint> puint;
typedef pair<ll, ll> pll;
typedef pair<pll, ll> plll;
typedef pair<pll, ld> plld;
typedef pair<ld, int> pldi;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ull, ull> pull;
typedef pair<ld, ld> pld;
typedef complex<double> cd;
//#define max(n, m) ((n>m)?n:m)
//#define min(n, m) ((n<m)?n:m)
#define f first
#define s second
#define input() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//#define eps 1e-8
//#define eps2 1e-15
#define leni(x) sizeof(x)/sizeof(int)
#define v(i,j,k) for(i=j;i<k;i++)
//#define cin fin
//#define cout fout
//#define fin cin
//#define fout cout
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")

/*

     ._________.
     |_________|
   ---------------
  |_____• U •_____|
 -------------------
|___________________|


 */

ifstream fin("schi.in");
ofstream fout("schi.out");

int n, nums[30010], ans[30010], bit[30010];
void update(int idx, int val)
{
    idx ++;
    while(idx <= n)
    {
        bit[idx] += val;
        idx += idx & (-idx);
    }
}
int main()
{
    fin >> n;
    for(int i = 0; i < n; i ++)
    {
        fin >> nums[i];
        nums[i]--;
    }
    int lg = (1<<(int)log2(n-1)), idx, cur;
    for(int i = 1; i <= n; i ++)
        bit[i] = (i) & (-i);
    for(int i = n-1; i >= 0; i --)
    {
        idx = cur = 0;
        for(int j = lg; j > 0; j >>= 1)
        {
            if(idx+j < n && cur + bit[idx+j] <= nums[i])
            {
                idx += j;
                cur += bit[idx];
            }
        }
        ans[idx] = i+1;
        update(idx, -1);
    }
    for(int i = 0; i < n; i ++)
        fout << ans[i] << endl;
}

/*
 7 1 1
 - 1 2
 8 1 1
 6 1 4
 - 1 1
 - 1 2
 5 1 1
 - 1 8
 */