Submission #201450

#TimeUsernameProblemLanguageResultExecution timeMemory
201450red1108Swap (BOI16_swap)C++17
100 / 100
781 ms3832 KiB
#include<bits/stdc++.h> #include<ext/rope> using namespace std; using namespace __gnu_cxx; #define fi first #define se second #define fastio ios_base::sync_with_stdio(false);cin.tie(0) #define fopen freopen("input.txt", "r", stdin) #define eb emplace_back #define em emplace #define prec(a) cout<<fixed;cout.precision(a); #define all(a) (a).begin(), (a).end() typedef long long ll;typedef long double ld;typedef unsigned long long ul;typedef unsigned int ui;typedef pair<int,int> pii;typedef pair<ll,ll> pll; typedef tuple<int,int,int> tiii; const ll INF = 2e18; const int inf = 2e9; template<class T> void pr(T t) {cout << t << " ";} template<class T, class ...Args> void pr(T a, Args ...args) {cout << a << " ";pr(args...);} template<class ...Args> void prl(Args ...args) {pr(args...);cout << endl;} int in[200010],n; int f(int x, int v){ if(x>n/2) return x; if(v<in[x*2]&&v<in[x*2+1]) return x; if(in[x*2]<v&&in[x*2]<in[x*2+1]) return f(x*2,v); if(v<in[x*2]) return min(f(x*2,v),f(x*2+1,v)); else{ int a = f(x*2,in[x*2]), b = f(x*2+1,in[x*2]); if(a<b) return f(x*2+1,v); else return f(x*2,v); } } int main(){ //freopen("input.txt","r",stdin); fastio; cin>>n; for(int i=1;i<=n;i++) cin>>in[i]; in[n+1]=n+1; for(int i=1;i<=n/2;i++){ if(in[i]<in[i*2]&&in[i]<in[i*2+1]) continue; if(in[i*2]<in[i]&&in[i*2]<in[i*2+1]){swap(in[i],in[i*2]);continue;} int x = min(in[i],in[i*2]),y=max(in[i],in[i*2]),z=in[i*2+1]; int a = f(i*2,x), b = f(i*2+1,x); if(a<b) {in[i*2]=x;in[i*2+1]=y;} else {in[i*2]=y;in[i*2+1]=x;} in[i]=z; } for(int i=1;i<=n;i++) cout<<in[i]<<" "; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...