| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 740863 | enerelt14 | 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 "perm.h"
#include<bits/stdc++.h>
#define ll long long
using namespace std;
vector<int> x;
vector<int> construct_permutation(ll k){
	if (k == 1)return {};
	if (k == 2)return {0};
	if (k == 3)return {1, 0};
	if (k % 4 == 0){
		x = construct_permutation(k / 4);
		x.pb(x.size());
		x.pb(x.size());
		return x;
	}
	if (k % 4 == 1){
		x = construct_permutation(k / 4);
		for (int i = 0; i < x.size(); i++)x[i]++;
		x.pb(x.size() + 1);
		x.pb(x.size() + 1);
		x.pb(0);
		return x;
	}
	if (k % 4 == 2){
		x = construct_permutation(k / 4);
		for (int i = 0; i < x.size(); i++)x[i]++;
		x.pb(x.size() + 1);
		x.pb(0);
		x.pb(x.size());
		return x;
	}
	x = construct_permutation(k / 4);
	for (int i = 0; i < x.size(); i++)x[i] += 2;
	x.pb(1);
	x.pb(x.size() + 1);
	x.pb(0);
	x.pb(x.size());
	return x;
}
