Submission #1249327

#TimeUsernameProblemLanguageResultExecution timeMemory
1249327duyanhloveavmedians (balkan11_medians)C++20
100 / 100
23 ms2372 KiB
#include <bits/stdc++.h>
using namespace std;

#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1LL)

using ll = long long;

const int mxn = 9 + 1e6;
const int inf = 0x3f3f3f3f;
const ll lnf = 0x3f3f3f3f3f3f3f3f;

template <class T>
struct Fenwick {
  vector<T> fenw;
  int n;
  Fenwick(int n) : n(n) { fenw.resize(n); }

  void upd(int x, T v) {
    for (; x < n; x |= x + 1) {
      fenw[x] += v;
    }
  }

  T get(int x) {
    T v{};
    for (; x >= 0; x &= x + 1, --x) {
      v += fenw[x];
    }
    return v;
  }
};

void _27augain(void) {
  int n;
  cin >> n;
  int l = 1, r = 2 * n - 1;
  vector<bool> used(r + 1);
  Fenwick<int> fenw(r + 1);
  for (int sz = 1; sz <= 2 * n - 1; sz += 2) {
    int x;
    cin >> x;
    if (!used[x]) {
      used[x] = true;
      fenw.upd(x, 1);
      cout << x << " ";
    }
    while (fenw.get(x - 1) < sz / 2) {
      while (used[l]) ++l;
      used[l] = true;
      fenw.upd(l, 1);
      cout << l << " ";
    }
    while (fenw.get(2 * n - 1) - fenw.get(x) < sz / 2) {
      while (used[r]) --r;
      used[r] = true;
      fenw.upd(r, 1);
      cout << r << " ";
    }
  }
}

int32_t main(void) {
#define task "27augain"
  cin.tie(0)->sync_with_stdio(0);
  for (string iext : {"in", "inp"}) {
    if (fopen((task "." + iext).c_str(), "r")) {
      freopen((task "." + iext).c_str(), "r", stdin);
      freopen(task ".out", "w", stdout);
    }
  }
  int testcase = 1;
  // cin >> testcase;
  while (testcase--) {
    _27augain();
  }
  return 0;
}

Compilation message (stderr)

medians.cpp: In function 'int32_t main()':
medians.cpp:68:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |       freopen((task "." + iext).c_str(), "r", stdin);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
medians.cpp:69:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |       freopen(task ".out", "w", stdout);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...