This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "perm.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<int> bits;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myrand(ll l , ll r)
{
return uniform_int_distribution<ll>(l , r)(rng);
}
void add(ll k)
{
if(k == 0)
{
return;
}
ll last = 1;
for(ll i = 59 ; i >= 1 ; i--)
{
if(k - ((1ll<<i) - 1) >= 0)
{
last = max(last , i);
}
if(k - ((1ll<<i) - 1) == 0)
{
bits.push_back(i);
return;
}
}
ll nb = myrand(max(1ll , last - 1) , last);
k -= ((1ll<<nb) - 1);
bits.push_back(nb);
add(k);
}
std::vector<int> construct_permutation(long long k)
{
k--;
bits.clear();
int n = 0;
add(k);
for(auto bit : bits)
n+=bit;
n--;
vector<int> perm;
for(auto i : bits)
{
for(int j = n - i + 1 ; j <= n ; j++)
{
perm.push_back(j);
}
n-=i;
}
return perm;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |