Submission #855815

#TimeUsernameProblemLanguageResultExecution timeMemory
855815beabossSwap (BOI16_swap)C++14
0 / 100
2 ms4956 KiB
// Source: https://oj.uz/problem/view/BOI16_swap // #include "bits/stdc++.h" using namespace std; #define s second #define f first #define pb push_back typedef long long ll; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef vector<int> vi; #define FOR(i, a, b) for (int i = (a); i<b; i++) const int N = 1e5; int a[N]; bool vis[N]; set<int> s[N]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; FOR(i, 1, n+1) { cin >> a[i]; s[i].insert(a[i]); } FOR(i, 1, n+1) { while (vis[*s[i].begin()]) s[i].erase(s[i].begin()); // cout << i << endl; if (2 * i + 1 <= n) assert(s[2*i].size() == 1 && s[2*i + 1].size() == 1); int opt = *s[i].begin(); if (2*i <= n) opt = min(*s[2*i].begin(), opt); if (2 * i + 1 <= n) opt = min(*s[2*i+1].begin(), opt); if (2*i <= n && *s[2 * i].begin() == opt) swap(s[i], s[2*i]); if (2 * i + 1 <= n && *s[2*i + 1].begin() == opt) { swap(s[i], s[2*i+1]); s[2*i+1].insert(*s[2*i].begin()); s[2*i] = s[2*i + 1]; } vis[*s[i].begin()]=true; cout << (*s[i].begin()) << ' '; } cout << endl; }
#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...