Submission #29205

#TimeUsernameProblemLanguageResultExecution timeMemory
29205Nirjhormedians (balkan11_medians)C++14
100 / 100
33 ms3604 KiB
#include <bits/stdc++.h> using namespace std; const int N = 200010; bitset <N> vis; int n, a[N], b[N], l, r; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", b + i); } a[1] = b[1]; l = 0, r = n + n; vis[b[1]] = vis[l] = vis[r] = 1; for (int i = 2, j = 2; i <= n; ++i, j += 2) { if (b[i] == b[i - 1]) { while (vis[l]) ++l; while (vis[r]) --r; a[j] = l, a[j + 1] = r; vis[l] = vis[r] = 1; } if (b[i] < b[i - 1]) { if (vis[b[i]]) { while (vis[l]) ++l; a[j] = l, vis[l] = 1; while (vis[l]) ++l; a[j + 1] = l, vis[l] = 1; } else { a[j] = b[i], vis[b[i]] = 1; while (vis[l]) ++l; a[j + 1] = l, vis[l] = 1; } } if (b[i] > b[i - 1]) { if (vis[b[i]]) { while (vis[r]) --r; a[j] = r, vis[r] = 1; while (vis[r]) --r; a[j + 1] = r, vis[r] = 1; } else { a[j] = b[i], vis[b[i]] = 1; while (vis[r]) --r; a[j + 1] = r, vis[r] = 1; } } } for (int i = 1; i < n + n; ++i) { printf("%d ", a[i]); } puts(""); return 0; }

Compilation message (stderr)

medians.cpp: In function 'int main()':
medians.cpp:11:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
                  ^
medians.cpp:13:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", b + i);
                       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...