Submission #563338

#TimeUsernameProblemLanguageResultExecution timeMemory
563338ngpin04Swap (BOI16_swap)C++14
0 / 100
5 ms9668 KiB
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define TASK "" #define bit(x) (1LL << (x)) #define getbit(x, i) (((x) >> (i)) & 1) #define ALL(x) (x).begin(), (x).end() using namespace std; template <typename T1, typename T2> bool mini(T1 &a, T2 b) { if (a > b) {a = b; return true;} return false; } template <typename T1, typename T2> bool maxi(T1 &a, T2 b) { if (a < b) {a = b; return true;} return false; } mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count()); int rand(int l, int r) { return l + rd() % (r - l + 1); } const int N = 2e5 + 5; const int oo = 1e9; const long long ooo = 1e18; const int mod = 1e9 + 7; // 998244353; const long double pi = acos(-1); set <int> s[N]; int root[N]; int pos[N]; int a[N]; int n; int main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifdef ONLINE_JUDGE // freopen(TASK".inp","r",stdin); // freopen(TASK".out","w",stdout); #endif cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++){ root[i] = i; s[i].insert(i); } for (int i = 1; 2 * i <= n; i++) { int r = root[a[i]]; a[i] = *s[r].begin(); // cerr << i << " " << a[i] << "\n"; if (2 * i + 1 > n) { if (a[i] > a[2 * i]) swap(a[i], a[2 * i]); continue; } int mn = min({a[i], a[2 * i], a[2 * i + 1]}); if (a[i] == mn) { // cerr << "ok\n"; s[r].erase(a[i]); } else if (a[2 * i] == mn) { // cerr << "left \n"; swap(a[i], a[2 * i]); } else { // cerr << "right \n"; swap(a[i], a[2 * i + 1]); root[a[2 * i]] = r; s[r].insert(a[2 * i]); } } for (int i = 1; i <= n; i++) if (2 * i > n) { int r = root[a[i]]; a[i] = *s[r].begin(); s[r].erase(a[i]); } for (int i = 1; i <= n; i++) cout << a[i] << " "; return 0; }
#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...