Submission #855814

# Submission time Handle Problem Language Result Execution time Memory
855814 2023-10-01T22:12:34 Z beaboss Swap (BOI16_swap) C++14
0 / 100
1 ms 4956 KB
// 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 && *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 time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Incorrect 1 ms 4952 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Incorrect 1 ms 4952 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Incorrect 1 ms 4952 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Incorrect 1 ms 4952 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Incorrect 1 ms 4952 KB Output isn't correct
4 Halted 0 ms 0 KB -