#include<bits/stdc++.h>
using namespace std;
const int MAXN=200101;
struct fenwick {
int arr[MAXN];
fenwick() {memset(arr,0,sizeof arr);}
void incr(int x, int by) {
for(;x<MAXN;x+=(x&(-x))) {
arr[x]+=by;
}
}
int sum(int x) {
int sum=0;
for(;x>0;x-=(x&(-x))) {
sum+=arr[x];
}
return sum;
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
vector<int> t(n);
for(int i=0;i<n;++i) cin>>t[i];
set<int> s;
for(int i=1;i<=2*n-1;++i) s.insert(i);
fenwick fw;
fw.incr(t[0], 1);
s.erase(t[0]);
vector<int> ans;
ans.push_back(t[0]);
auto med=[&]() -> int {
int all=fw.sum(MAXN-1);
int kell=(all+1)/2;
int akt=MAXN-1;
for(int i=20;i>=0;i--) {
int curr=akt-(1<<i);
if(curr>=1) {
if(fw.sum(curr)>=kell) {
akt=curr;
}
}
}
return akt;
};
auto addmin=[&](){
int val=*s.begin();
s.erase(val);
fw.incr(val, 1);
ans.push_back(val);
};
auto addmax=[&](){
auto it=s.end();
it--;
int val=*it;
s.erase(val);
fw.incr(val, 1);
ans.push_back(val);
};
for(int i=1;i<n;++i) {
if(s.find(t[i])==s.end()) {
if(med()<t[i]) {
addmin();
addmin();
}else if(med()>t[i]) {
addmax();
addmax();
}else {
addmin();
addmax();
}
}else {
s.erase(t[i]);
fw.incr(t[i], 1);
ans.push_back(t[i]);
if(med()<=t[i]) addmin();
else addmax();
}
}
for(auto i:ans) {
cout<<i<<" ";
}
cout<<"\n";
/*
for(int i=0;i<(int)ans.size();i+=2) {
vector<int> akt;
for(int j=0;j<=i;++j) akt.push_back(ans[j]);
sort(akt.begin(), akt.end());
cerr<<akt[akt.size()/2]<<" ";
}cerr<<"\n";*/
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1152 KB |
Output is correct |
2 |
Incorrect |
3 ms |
1152 KB |
Output isn't correct |
3 |
Incorrect |
3 ms |
1152 KB |
Output isn't correct |
4 |
Incorrect |
3 ms |
1152 KB |
Output isn't correct |
5 |
Incorrect |
3 ms |
1152 KB |
Output isn't correct |
6 |
Correct |
3 ms |
1152 KB |
Output is correct |
7 |
Incorrect |
3 ms |
1152 KB |
Output isn't correct |
8 |
Incorrect |
3 ms |
1152 KB |
Output isn't correct |
9 |
Incorrect |
3 ms |
1152 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
1152 KB |
Output isn't correct |
11 |
Incorrect |
3 ms |
1152 KB |
Output isn't correct |
12 |
Incorrect |
4 ms |
1196 KB |
Output isn't correct |
13 |
Incorrect |
3 ms |
1152 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
1408 KB |
Output isn't correct |
2 |
Incorrect |
6 ms |
1664 KB |
Output isn't correct |
3 |
Incorrect |
11 ms |
1920 KB |
Output isn't correct |
4 |
Incorrect |
21 ms |
2808 KB |
Output isn't correct |
5 |
Incorrect |
39 ms |
4600 KB |
Output isn't correct |
6 |
Incorrect |
97 ms |
8324 KB |
Output isn't correct |
7 |
Incorrect |
152 ms |
12252 KB |
Output isn't correct |