Submission #258598

#TimeUsernameProblemLanguageResultExecution timeMemory
258598IOrtroiiiSwap (BOI16_swap)C++14
0 / 100
0 ms384 KiB
#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 (stderr)

swap.cpp: In function 'int main()':
swap.cpp:61:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    for (int i = 1; i <= N; ++i) cout << ans[i] << ' '; cout << '\n';
    ^~~
swap.cpp:61:56: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
    for (int i = 1; i <= N; ++i) cout << ans[i] << ' '; cout << '\n';
                                                        ^~~~
swap.cpp: In function 'int query(int)':
swap.cpp:22:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#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...