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 <bits/stdc++.h>
#define endl '\n'
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define fo(i,n) for(auto i =0 ; i < n;i++)
#define fore(i,l,r) for(auto i = l; i < r;i++)
#define forex(i,r,l) for(auto i = r; i >= l; i--)
#define ffo(i,n) forex(i,n-1,0)
#define all(x) x.begin(),x.end()
#define lsb(x) x&(-x)
#define sz(x) (int)x.size()
#define gcd(a,b) __gcd(a,b)
#define vii vector<ii>
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>;using ii = pair<int,int>;using mii = map<int,int>;
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
vi construct_permutation(ll k){
int act = 0;
vi ot;ll otk = k;
while(otk>1){
// cout<<otk<<endl;cout.flush();
ll lg = 1, p2 = 2;
while(p2*2 <= otk)p2*=2, lg++;
vi ins;fo(i,lg)ins.pb(act),act++;
reverse(all(ins));
for(int v : ins)ot.pb(v);
otk-=p2;otk++;
}reverse(all(ot));
vi ans;act=0;
ll lg = 1, p2 = 2;
while(p2*2 <= k)p2*=2, lg++;
int n = lg;k-= 1ll<<lg;
for(ll i = 0 ; i <= lg; i++) if(k &(1ll<<i))n++;
for(ll i = 0; i < lg; i++){
if(k&(1ll<<i)){ans.pb(n-1);n--;}
ans.pb(act);act++;
}
if(sz(ot)<sz(ans)) return ot;
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |