# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
658341 | Zena_Hossam | Permutation (APIO22_perm) | C++17 | 248 ms | 262144 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)
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
vector<pair<ll,int>>v;
vector<int>s,x;
long long l=1;
for(int i=0;i<100;i++)
{
v.push_back({l-1,i});
l*=2;
if(l-1>1e18)break;
}
ll p=k-2;k--;
while(1)
{
pair<ll,int>h={k,0};
int o=upper_bound(v.begin(),v.end(),h)-v.begin();
while(v[o].first>k&&k)o--;
while(k>=v[o].first){
for(int i=p-v[o].second+1;i<=p;i++){
s.push_back(i);
}
p-=v[o].second;
k-=v[o].first;}
if(k<=0)break;
}
for(int i=0;i<s.size();i++)
{
s[i]-=(p+1);
}
return s;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |