# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
258598 | 2020-08-06T08:04:34 Z | IOrtroiii | Swap (BOI16_swap) | C++14 | 0 ms | 384 KB |
#include <bits/stdc++.h> using namespace std; const int MX = 400400; int N; int A[MX]; int state[MX]; int ans[MX]; int query(int i) { int ans = MX; for (; i > 0; i /= 2) { if (state[i] != 1) ans = min(ans, A[i]); if (state[i] == 0) return ans; if (i % 2 && state[i - 1] != 0) { ans = min(ans, A[i - 1]); if (state[i - 1] == 1) return ans; } } } void modify(int i, int val) { for (; i > 0; i /= 2) { if (A[i] == val) { state[i] = 0; return; } if (i % 2) { if (A[i - 1] == val) { state[i] = state[i - 1] = 1; return; } else state[i - 1] = 0; } state[i] = 1; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> N; for (int i = 1; i <= N; ++i) cin >> A[i]; for (int i = N + 1; i <= 2 * N + 1; ++i) A[i] = MX; state[1] = 0; for (int i = 2; i <= 2 * N + 1; ++i) state[i] = -1; for (int i = 1; i <= N; ++i) { int val = query(i); ans[i] = min({val, A[i * 2], A[i * 2 + 1]}); if (ans[i] == val) { modify(i, val); state[i * 2] = 0; state[i * 2 + 1] = 0; } else if (ans[i] == A[i * 2]) { state[i * 2] = 1; state[i * 2 + 1] = 1; } else { assert(ans[i] == A[i * 2 + 1]); state[i * 2 + 1] = 1; } } for (int i = 1; i <= N; ++i) cout << ans[i] << ' '; cout << '\n'; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |