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 N 200005
using namespace std;
vector<int> create(int a,int b){
if(b == 1){
return {a};
}
auto l = create(a-1,b/2);
auto r = create(a-1,b-b/2);
for(auto u:r){
l.push_back(u);
}
return l;
}
void solve(){
int n,k;
cin >> n >> k;
vector<int> v;
vector<int> now = {30};
for(int i = 1;i<=n;i++){
int x;
cin >> x;
while(now.back() < x){
v.push_back(now.back());
now.pop_back();
}
while(now.back() > x){
int tmp = now.back()-1;
now.pop_back();
now.push_back(tmp);
now.push_back(tmp);
}
v.push_back(now.back());
now.pop_back();
}
int needed = n + k - now.size() - v.size();
for(auto u:now){
auto tmp = create(u,min(1<<u,needed+1));
for(auto u:tmp){
v.push_back(u);
}
needed -= min(1<<u,needed+1) - 1;
}
for(auto u:v){
cout << u << " ";
}
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t=1;
//cin>>t;
while(t--){
solve();
}
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |