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 "perm.h"
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pi;
typedef vector<pi> pii;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair
ll INF=1e18+10;
std::vector<int> construct_permutation(long long k)
{
if(k==1)return {};
//k--;
vi ans;
int pos=-1;
vector<ll> a(70,INF);
REP(i,0,64)a[i]=pow(2,i);
bool flag=1;
int it=lower_bound(a.begin(),a.end(),k)-a.begin();
if(a[it]!=k)it--;
k-=a[it];
pos+=it;
int pos2=pos;
while(it){
ans.PB(pos);
pos--;
it--;
}
pos=pos2;
reverse(ans.begin(),ans.end());
while(k){
pos++;
int it=lower_bound(a.begin(),a.end(),k)-a.begin();
if(a[it]!=k)it--;
k-=a[it];
ans.insert(ans.begin()+it,pos);
}
//REP(i,0,ans.size())cout<<ans[i]<<" ";
return ans;
}
Compilation message (stderr)
perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:30:10: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<long long unsigned int>, long long unsigned int>::value_type' {aka 'long long unsigned int'} and 'long long int' [-Wsign-compare]
30 | if(a[it]!=k)it--;
perm.cpp:44:11: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<long long unsigned int>, long long unsigned int>::value_type' {aka 'long long unsigned int'} and 'long long int' [-Wsign-compare]
44 | if(a[it]!=k)it--;
perm.cpp:27:7: warning: unused variable 'flag' [-Wunused-variable]
27 | bool flag=1;
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |