# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
911482 | weakweakweak | Permutation (APIO22_perm) | C++17 | 0 ms | 0 KiB |
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>
using namespace std;
#define int long long
#define fs first
#define sc second
#define pii pair<int,int>
vector<int> main(int n){
vector<int>v;
int dd=1;
while(dd*2<=n){
v.push_back(v.size()+1);
dd*=2;
}
int id=0, zz=10000;
n-=dd;
int z=v.size();
id=-1;
for(int i=0, dd=1; i<=z; i++, zz--, dd*=2){
while(i!=0 and v[id]!=i and id+1<=v.size())id++;
if(n&dd){
// cout << i << ' ' << id << ' ' << v[id] << '\n';
v.insert(v.begin()+id+1,zz);
}
if(i==0)id=0;
}
return v;
}