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>
using namespace std;
const int N = 200010;
vector <int> v[N];
int p[N];
int mark[N];
int main(){
int n;
cin >> n;
for(int i = 1;i <= n;i++){
cin >> p[i];
v[i].push_back(p[i]);
}
for(int i = 2;i <= n;i++){
set <int> s;
for(auto x : v[i]){
s.insert(x);
}
for(auto x : v[i/2]){
s.insert(x);
}
v[i/2].clear();
v[i].clear();
for(auto x : s){
v[i/2].push_back(x);
v[i].push_back(x);
}
}
vector <int> res;
for(int i = n;i >= 1;i--){
sort(v[i].begin(), v[i].end());
reverse(v[i].begin(), v[i].end());
/*for(auto x : v[i]){
cout << x << ' ';
}
cout << '\n';*/
for(auto x : v[i]){
if(mark[x] == 0){
res.push_back(x);
mark[x] = 1;
break;
}
}
}
reverse(res.begin(), res.end());
for(auto x : res){
cout << x << ' ';
}
cout << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |