Submission #833196

#TimeUsernameProblemLanguageResultExecution timeMemory
833196christinelynnPermutation (APIO22_perm)C++17
71.22 / 100
10 ms1364 KiB
#include "perm.h" #include<bits/stdc++.h> using namespace std; long long binpow(long long base, int exp) { long long ret=1; while(exp) { if(exp&1) ret*=base; base*=base; exp>>=1; } return ret; } vector<int> construct_permutation(long long k) { vector<int> ans; k--; int mx=0; while(k) { int l=0, r=59, len=0; while(l<=r) { int mid=l+r>>1; if(binpow(2, mid)-1<=k) len=mid, l=mid+1; else r=mid-1; } mx-=len; for(int i=mx+1; i<=mx+len; i++) ans.push_back(i); k-=binpow(2, len)-1; } for(int &p : ans) p-=mx+1; return ans; }

Compilation message (stderr)

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:19:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   19 |       int mid=l+r>>1;
      |               ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...