Submission #912388

#TimeUsernameProblemLanguageResultExecution timeMemory
912388huyngoPermutation (APIO22_perm)C++17
91.33 / 100
2 ms600 KiB
#include "perm.h"
#include <bits/stdc++.h>  
using namespace std;
using ll = long long;
using i64 = long long;
#define ln "\n"
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for(int i=a; i<=b; ++i)

const int mxN = 1e6 + 5;
int n;

vector<int> construct_permutation(long long k) {
	vector<int> ans;
	int l = 0, r = 0;
	auto work = [&](auto self, ll x) -> void {
		if (x == 1) return;
		if (x & 1) {
			self(self, x - 1);
			ans.push_back(--l);
		}
		else {
			self(self, x >> 1);
			ans.push_back(++r);
		}
		};
	work(work, k);
	vector<int> s = ans;
	sort(all(s));
	s.erase(unique(all(s)), s.end());
	for (int& i : ans)
		i = lower_bound(all(s), i) - s.begin();
	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...