Submission #330767

#TimeUsernameProblemLanguageResultExecution timeMemory
330767BeanZmedians (balkan11_medians)C++14
100 / 100
32 ms3564 KiB
// I_Love_LPL #include <bits/stdc++.h> using namespace std; #define ll int #define endl '\n' const int N = 2e5 + 5; const int lg = 60; const int mod = 998244353; const long long oo = 1e18; const int lim = 1e6 + 5; long double eps = 1e-3; ll vis[N], b[N], a[N]; ll l, r; void addl(ll id){ while (vis[l]) l++; b[id] = l; vis[l] = 1; } void addr(ll id){ while (vis[r]) r--; b[id] = r; vis[r] = 1; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("test.inp", "r")){ freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } ll n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; b[1] = a[1]; vis[b[1]] = 1; l = 1, r = 2 * n - 1; for (int i = 2; i <= n; i++){ if (a[i] == a[i - 1]){ addl(i * 2 - 2); addr(i * 2 - 1); } else if (a[i] > a[i - 1]){ if (vis[a[i]]){ addr(i * 2 - 2); addr(i * 2 - 1); } else { vis[a[i]] = 1; b[i * 2 - 2] = a[i]; addr(i * 2 - 1); } } else { if (vis[a[i]]){ addl(i * 2 - 2); addl(i * 2 - 1); } else { vis[a[i]] = 1; b[i * 2 - 2] = a[i]; addl(i * 2 - 1); } } } for (int i = 1; i <= (2 * n - 1); i++) cout << b[i] << " "; } /* */

Compilation message (stderr)

medians.cpp: In function 'int main()':
medians.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   28 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
medians.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   29 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...