Submission #785322

#TimeUsernameProblemLanguageResultExecution timeMemory
785322mindiyakPermutation (APIO22_perm)C++17
0 / 100
1 ms212 KiB
#include "perm.h" #include <cmath> #include <deque> #include <iostream> #define ll long long #define pb push_back using namespace std; int binary_search(ll val){ int l = 0,r = 61; while(l<r){ int mid = (l+r) >> 1; // cout << val << " " << l << " " << mid << " " << r << endl; if(val < pow(2,mid)){ r = mid-1; }else{ l = mid+1; } } // cout << "lenght " << l << endl << endl; return l; } std::vector<int> construct_permutation(long long k) { deque<pair<int,int>> ans; int n = 0; while(k > 0){ int temp = binary_search(k)-1; ans.push_front({n,n+temp}); k -= pow(2,temp+1); n += temp + 1; } vector<int> arr; for(int i=0;i<ans.size();i++){ // cout << ans[i].first << " " << ans[i].second << endl; for(int j=ans[i].first;j<=ans[i].second;j++){ arr.pb(j); } } // for(int i=0;i<arr.size();i++){ // cout << arr[i] << " "; // } cout << endl; return arr; }

Compilation message (stderr)

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:35:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |  for(int i=0;i<ans.size();i++){
      |              ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...