# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
134252 | Kastanda | Swap (BOI16_swap) | C++11 | 90 ms | 6776 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// ItnoE
#include<bits/stdc++.h>
using namespace std;
const int N = 400005;
int n, A[N], R[N], M[N];
inline int GetBest(int id)
{
int Mn = INT_MAX;
while (id)
{
if (M[id] != 1)
Mn = min(Mn, A[id]);
if (!M[id])
break;
if ((id & 1) && M[id ^ 1])
{
Mn = min(Mn, A[id ^ 1]);
if (M[id ^ 1] == 1)
break;
}
id >>= 1;
}
return (Mn);
}
inline void Del(int id, int val)
{
while (id)
{
if (A[id] == val)
{M[id] = 0; break;}
if (id & 1)
{
if (A[id ^ 1] == val)
{M[id ^ 1] = M[id] = 1; break;}
else
M[id ^ 1] = 0;
}
M[id] = 1;
id >>= 1;
}
}
int main()
{
scanf("%d", &n);
memset(A, 63, sizeof(A));
for (int i = 1; i <= n; i ++)
scanf("%d", &A[i]), M[i] = 2;
M[1] = 0;
for (int i = 1; i <= n; i ++)
{
int lc = i << 1, rc = lc ^ 1;
int Mn = min({GetBest(i), A[lc], A[rc]});
R[i] = Mn;
if (Mn == GetBest(i))
M[lc] = M[rc] = 0, Del(i, Mn);
if (Mn == A[lc])
M[lc] = 1, M[rc] = 0;
if (Mn == A[rc])
M[rc] = 1;
}
for (int i = 1; i <= n; i ++)
printf("%d ", R[i]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |