Submission #134252

#TimeUsernameProblemLanguageResultExecution timeMemory
134252KastandaSwap (BOI16_swap)C++11
100 / 100
90 ms6776 KiB
// 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)

swap.cpp: In function 'int main()':
swap.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
swap.cpp:47:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &A[i]), M[i] = 2;
         ~~~~~~~~~~~~~~~~~~^~~~~~~~~~
#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...