#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
using namespace std;
// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
typedef vector<int> vi;
#define f first
#define s second
// END NO SAD
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<ll>> matrix;
const int SZ = 1 << 17;
int tree[2 * SZ];
void upd(int idx) {
idx += SZ;
while(idx) {
tree[idx]++;
idx /= 2;
}
}
int qry(int lhs, int rhs) {
int ret = 0;
lhs += SZ;
rhs += SZ;
while(lhs <= rhs) {
if(lhs%2) ret += tree[lhs++];
if(rhs%2==0) ret += tree[rhs--];
lhs /= 2;
rhs /= 2;
}
return ret;
}
void solve() {
int n;
cin >> n;
set<int> s;
for(int i = 1; i < 2*n; i++) s.insert(i);
vector<int> ret;
for(int a = 1; a <= n; a++) {
int x;
cin >> x;
if(s.count(x)) {
ret.pb(x); upd(ret.back()); s.erase(ret.back());
}
while(qry(1, x-1) < a-1) {
ret.pb(*s.begin()); upd(ret.back()); s.erase(ret.back());
}
while(sz(ret) < 2*a-1) {
ret.pb(*s.rbegin()); upd(ret.back()); s.erase(ret.back());
}
}
for(int i = 0; i < sz(ret); i++) cout << ret[i] << " \n"[i == sz(ret)-1];
}
// !editcommand?
// are there edge cases (N=1?)
// are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// integer overflow?
// DS reset properly between test cases
// are you doing geometry in floating points
// are you not using modint when you should
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
620 KB |
Output is correct |
2 |
Correct |
5 ms |
876 KB |
Output is correct |
3 |
Correct |
9 ms |
1388 KB |
Output is correct |
4 |
Correct |
18 ms |
2412 KB |
Output is correct |
5 |
Correct |
38 ms |
4600 KB |
Output is correct |
6 |
Correct |
77 ms |
8556 KB |
Output is correct |
7 |
Runtime error |
67 ms |
21484 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |