Submission #1363385

#TimeUsernameProblemLanguageResultExecution timeMemory
1363385Mamikonm1Permutation (APIO22_perm)C++20
64.63 / 100
4 ms1092 KiB
//#include<game>
#include <iostream>
#include <vector>
#include <cmath>
#include<map>
#include <algorithm>
#include <iomanip>
#include <string>
#include<stack>
#include <set>
#include <queue>
#include <chrono>
#include<array>
#include<bitset>
#include<unordered_map>
#include<random>
#include<cassert>
#include<cstring>
using namespace std;
using ll = long long;
using db = double;
const float pi = 3.14159265359;
#define V vector
#define VI V<int>
#define P pair<int,int>
#define rep(i, a, b, step) for (int i = int(a); i <= int(b); i += step)
#define repl(i,a,b,step) for (int i = int(a); i >= int(b); i -= step)
#define sn << '\n'
#define ed << endl
#define sz size()
#define print cout <<
#define debug(x) cerr<< #x << " = " << x sn;
#define mpII map<int,int>   
#define mine min_element    
#define maxe max_element    
#define all(v) begin(v), end(v)
#define txt freopen("snakes.in", "r", stdin); freopen("snakes.out", "w", stdout)    
#define pb push_back    
#define pq priority_queue
#define rev reverse
#define nuyn(a) a.erase(unique(all(a)), end(a))
#define nx next_permutation         
#define pk pop_back()
#define START print "Start" sn
#define END print "End" sn
#define ff first
#define ss second       
#define ts to_string 
#define ub upper_bound       
#define mk make_pair 
#define lb lower_bound               
#define testcase int t;cin>>t;while(t--)solution();
deque<int>an;
VI ans;
int n;
void rec(ll k) {
    if (k == 1)return;
    int cnt = 0;
    rep(i, 0, 60, 1) {
        if (k & (1ll << i)) {
            cnt++;
            if (!i)continue;
            repl(j, n + i, n + 1, 1)an.push_front(j);
            n += i;
        }
    }
    rep(i, n + 1, n + cnt - 1, 1)an.push_front(i);
}
std::vector<int> construct_permutation(long long k)
{
    n = -1;
    ans.clear();
    an.clear();
    rec(k);
    for (auto& i : an)ans.pb(i);
    return ans;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...