# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
658327 | Zena_Hossam | Permutation (APIO22_perm) | C++17 | 0 ms | 0 KiB |
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<bits/stdc++.h>
#include "perm.h"
#include "grader.cpp"
#define ll long long
using namespace std;
std::vector<int> construct_permutation(long long k)
{
ll p=k-2;k--;
vector<int>s,x;
while(1)
{
ll l=0,r=100,p1,h;
while(l<=r)
{
ll mid=(l+r)/2;
p1=(1<<mid)-1;
if(k>=p1)
{
h=mid;
l=mid+1;
}
else r=mid-1;
}
for(ll i=p-h+1;i<=p;i++){
s.push_back(i);
}
// cout<<v[o].first<<" "<<v[o].second<<" "<<k<<"\n";
p-=h;
k-=((1<<h)-1);
if(k<=0)break;
}
for(ll i=0;i<s.size();i++)
{
s[i]-=(p+1);
}
return s;
}