Submission #699132

#TimeUsernameProblemLanguageResultExecution timeMemory
699132dxz05Permutation (APIO22_perm)C++17
71.22 / 100
12 ms1320 KiB
#include "perm.h"
#include <bits/stdc++.h>

using namespace std;

vector<int> construct_permutation(long long k){
	int lg = 63 - __builtin_clzll(k);

	k--;

	vector<int> blocks;

	int x = 61;
	while (k > 0){
		if (k >= (1ll << x) - 1){
			k -= (1ll << x) - 1;
			blocks.push_back(x);
			x++;
		}
		x--;
	}

	vector<int> res;
	for (int sz : blocks){
		int val = res.size() + sz - 1;
		for (int i = 0; i < sz; i++){
			res.push_back(val--);
		}
	}

	reverse(res.begin(), res.end());

	return res;
}

Compilation message (stderr)

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:7:6: warning: unused variable 'lg' [-Wunused-variable]
    7 |  int lg = 63 - __builtin_clzll(k);
      |      ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...