//
// Created by 42kangaroo on 28/10/2023.
//
#include "bits/stdc++.h"
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, k; cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<pair<int,int>> addBef;
stack<pair<int,int>> st;
auto mergeBack= [&st](){
while (st.size()> 1){
auto t = st.top();
st.pop();
if (st.top().second == t.second) {
st.top().second++;
} else {
st.push(t);
break;
}
}
};
for (int i = 0; i < n; ++i) {
while (!st.empty() && st.top().second < a[i]) {
addBef.push_back(st.top());
st.push({-1, st.top().second});
mergeBack();
}
st.push({i, a[i]});
mergeBack();
}
while (!st.empty() && st.top().second < 30) {
addBef.push_back(st.top());
st.push({-1, st.top().second});
mergeBack();
}
vector<int> out;
int addInd = 0;
bool first = true;
for (int i = 0; i < n; ++i) {
while (addBef[addInd].first == i) {
if (first) {
int ks = k - addBef.size() + 1;
int p2 = 1;
for (int j = 0; j <= 30; ++j, p2*= 2) {
if (p2 >= ks) {
for (int l = 0; l < ks; ++l) {
if (l < p2 - ks - 1) out.push_back(addBef[addInd].second - j - 1);
else out.push_back(addBef[addInd].second - j);
}
break;
}
}
first = false;
addInd++;
} else {
out.push_back(addBef[addInd++].second);
}
}
out.push_back(a[i]);
}
for (auto e: out) {
cout << e << " ";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
10436 KB |
Output is correct |
2 |
Correct |
105 ms |
10360 KB |
Output is correct |
3 |
Correct |
105 ms |
10620 KB |
Output is correct |
4 |
Correct |
133 ms |
10436 KB |
Output is correct |
5 |
Correct |
107 ms |
10392 KB |
Output is correct |
6 |
Correct |
122 ms |
10352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
105 ms |
10436 KB |
Unexpected end of file - int32 expected |
2 |
Incorrect |
105 ms |
10440 KB |
Unexpected end of file - int32 expected |
3 |
Incorrect |
128 ms |
10448 KB |
Unexpected end of file - int32 expected |
4 |
Incorrect |
112 ms |
10636 KB |
Unexpected end of file - int32 expected |
5 |
Incorrect |
105 ms |
10432 KB |
Unexpected end of file - int32 expected |
6 |
Incorrect |
112 ms |
10360 KB |
Unexpected end of file - int32 expected |
7 |
Incorrect |
105 ms |
10432 KB |
Unexpected end of file - int32 expected |
8 |
Incorrect |
105 ms |
10436 KB |
Unexpected end of file - int32 expected |
9 |
Incorrect |
92 ms |
9992 KB |
Unexpected end of file - int32 expected |
10 |
Incorrect |
63 ms |
9028 KB |
Unexpected end of file - int32 expected |
11 |
Incorrect |
80 ms |
9312 KB |
Unexpected end of file - int32 expected |
12 |
Incorrect |
48 ms |
8380 KB |
Unexpected end of file - int32 expected |
13 |
Incorrect |
49 ms |
8376 KB |
Unexpected end of file - int32 expected |
14 |
Incorrect |
48 ms |
8388 KB |
Expected EOF |