# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
199003 | TadijaSebez | Swap (BOI16_swap) | C++11 | 6 ms | 504 KiB |
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;
#define pb push_back
#define mp make_pair
const int inf=1e9+7;
pair<int,int> min(pair<int,int> a,pair<int,int> b){return a<b?a:b;}
vector<int> mrg(vector<int> a,vector<int> b){
while(b.size())a.pb(b.back()),b.pop_back();
return a;
}
int main(){
int n;
scanf("%i",&n);
vector<vector<int>> a(n*2+5,vector<int>(0));
vector<bool> was(n+1,0);
for(int i=1,j;i<=n;i++)scanf("%i",&j),a[i].pb(j);
for(int i=n+1;i<a.size();i++)a[i].pb(inf);
for(int i=1;i<=n;i++){
sort(a[i].rbegin(),a[i].rend());
while(was[a[i].back()])a[i].pop_back(),assert(a[i].size());
int ch=i<<1|1;
if(a[i<<1][0]<a[i<<1|1][0])ch=i<<1;
if(a[ch][0]<a[i].back()){
if(ch&1){
vector<int> tmp=mrg(a[i],a[ch^1]);
a[i]=a[ch];
a[ch]=a[ch^1]=tmp;
}else{
swap(a[i],a[ch]);
}
}else{
int my=a[i].back();
a[i].clear();
a[i].pb(my);
}
was[a[i][0]]=1;
printf("%i ",a[i][0]);
}
return 0;
}
Compilation message (stderr)
# | 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... |