Submission #618075

#TimeUsernameProblemLanguageResultExecution timeMemory
618075LoboPermutation (APIO22_perm)C++17
91.33 / 100
113 ms424 KiB
#include "perm.h"
#include<iostream>
#include<vector>
#include<deque>
using namespace std;
#define int long long

vector<int32_t> construct_permutation(int k)
{
	int k1 = k;
	int k2 = 1;
	for(int i = min(k-1,(int) 1e5); i >= 1; i--) {
		if(k%i == 0) {
			k1 = i;
			k2 = k/i;
			break;
		}
	}
    vector<int32_t> vc;
    deque<int> ans;
    int lg = 0;
    for(int i = 0; i <= 60; i++) {
    	if(k1 >= (1LL<<i)) lg = i;
    }
    for(int i = lg-1; i >= 0; i--) {
        ans.push_back((int) ans.size());
        if(k1&(1LL<<i)) ans.push_front((int) ans.size());
    }
    // cout << "   " << k1 << endl;
    for(auto x : ans) {
    	// cout << " 1 " << x << endl;
    	vc.push_back(x);
    }

    deque<int> ans2;
    int lg2 = 0;
    for(int i = 0; i <= 60; i++) {
    	if(k2 >= (1LL<<i)) lg2 = i;
    }
    for(int i = lg2-1; i >= 0; i--) {
        ans2.push_back((int) ans2.size()+vc.size());
        if(k2&(1LL<<i)) ans2.push_front((int) ans2.size()+vc.size());
    }
    // cout << "   " << k2 << endl;
    for(auto x : ans2) {
    	// cout << " 2 " << x << endl;
    	vc.push_back(x);
    }

    return vc;

}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...