#include<bits/stdc++.h>
using namespace std;
int bit[200005],n;
void update(int now,int val){
for(int i=now;i<=2*n;i+=(i&(-i)))bit[i]+=val;
}
int query(int now){
int ret=0;
for(int i=now;i>0;i-=(i&(-i)))ret+=bit[i];
return ret;
}
set<int> available;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int a;
cin >> n >> a;
cout << a;
update(a,1);
for(int i=1;i<2*n;i++){
if(i!=a)available.insert(i);
}
for(int i=2;i<=n;i++){
cin >> a;
if(available.count(a)){
cout << " " << a;
update(a,1);
available.erase(a);
int brp=i-query(a);
if(brp==0){
auto it=available.end();
--it;
cout << " " << *it;
update(*it,1);
available.erase(it);
}
else{
auto it=available.begin();
cout << " " << *it;
update(*it,1);
available.erase(it);
}
}
else{
int brp=i-query(a);
if(brp==0){
auto it=available.end();
--it;
cout << " " << *it;
update(*it,1);
available.erase(it);
auto it2=available.end();
--it2;
cout << " " << *it2;
update(*it2,1);
available.erase(it2);
}
else if(brp==1){
auto it=available.begin();
cout << " " << *it;
update(*it,1);
available.erase(it);
auto it2=available.end();
--it2;
cout << " " << *it2;
update(*it2,1);
available.erase(it2);
}
else{
auto it=available.begin();
cout << " " << *it;
update(*it,1);
available.erase(it);
auto it2=available.begin();
cout << " " << *it2;
update(*it2,1);
available.erase(it2);
}
}
}
cout << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
396 KB |
Output is correct |
2 |
Correct |
1 ms |
492 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 |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
620 KB |
Output is correct |
2 |
Correct |
4 ms |
876 KB |
Output is correct |
3 |
Correct |
10 ms |
1260 KB |
Output is correct |
4 |
Correct |
18 ms |
2284 KB |
Output is correct |
5 |
Correct |
29 ms |
4204 KB |
Output is correct |
6 |
Correct |
59 ms |
8044 KB |
Output is correct |
7 |
Correct |
137 ms |
12524 KB |
Output is correct |