結果

問題 No.702 中央値を求めよ LIMITED
ユーザー 0w10w1
提出日時 2018-10-30 16:52:06
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 562 ms / 5,000 ms
コード長 1,733 bytes
コンパイル時間 1,988 ms
コンパイル使用メモリ 198,080 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-14 21:48:15
合計ジャッジ時間 18,796 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 560 ms
4,380 KB
testcase_01 AC 559 ms
4,380 KB
testcase_02 AC 560 ms
4,384 KB
testcase_03 AC 561 ms
4,380 KB
testcase_04 AC 562 ms
4,384 KB
testcase_05 AC 562 ms
4,384 KB
testcase_06 AC 560 ms
4,380 KB
testcase_07 AC 561 ms
4,384 KB
testcase_08 AC 560 ms
4,380 KB
testcase_09 AC 560 ms
4,380 KB
testcase_10 AC 560 ms
4,380 KB
testcase_11 AC 560 ms
4,376 KB
testcase_12 AC 560 ms
4,380 KB
testcase_13 AC 560 ms
4,376 KB
testcase_14 AC 560 ms
4,380 KB
testcase_15 AC 560 ms
4,376 KB
testcase_16 AC 560 ms
4,380 KB
testcase_17 AC 561 ms
4,384 KB
testcase_18 AC 560 ms
4,376 KB
testcase_19 AC 560 ms
4,376 KB
testcase_20 AC 560 ms
4,380 KB
testcase_21 AC 560 ms
4,380 KB
testcase_22 AC 561 ms
4,384 KB
testcase_23 AC 560 ms
4,380 KB
testcase_24 AC 561 ms
4,376 KB
testcase_25 AC 561 ms
4,384 KB
testcase_26 AC 560 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template <typename T>
class Array : public vector<T> {
 public:
  using vector<T>::vector;
  using vector<T>::begin;
  using vector<T>::end;
  using vector<T>::push_back;
  template <typename R>
  Array<R> map(function<R(T)> f) {
    Array<R> res(end() - begin());
    for (auto it = begin(); it != end(); ++it) res[it - begin()] = f(*it);
    return res;
  }
  Array<T> select(function<bool(T)> f) {
    Array<T> res;
    for (auto it = begin(); it != end(); ++it)
      if (f(*it)) res.push_back(*it);
    return res;
  }
  template <typename R>
  R reduce(R u, function<R(R, T)> f) {
    for (auto it = begin(); it != end(); ++it) u = f(u, *it);
    return u;
  }
  template <typename U>
  Array<pair<T, U>> zip(const Array<U> &b) {
    assert(end() - begin() == b.end() - b.begin());
    Array<pair<T, U>> res;
    for (auto it = begin(); it != end(); ++it)
      res.push_back({*it, b[it - begin()]});
    return res;
  }
  Array<T> iota(T st) {
    Array<T> res(end() - begin());
    ::iota(res.begin(), res.end(), st);
    return res;
  }
};

signed main() {
  ios::sync_with_stdio(false);

  int seed;
  cin >> seed;

  struct Rng {
    uint32_t x, y, z, w;
    Rng(int seed) : x(seed), y(1), z(2), w(3) {}
    uint32_t generate() {
      uint32_t t = (x ^ (x << 11));
      x = y;
      y = z;
      z = w;
      w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
      return w;
    }
  };

  const int N = 10000001;

  uint64_t lb = 0, ub = 1ULL << 32;
  while (ub - lb > 1) {
    Rng rng(seed);
    uint64_t mb = lb + ub >> 1;
    int lcnt = 0;
    for (int i = 0; i < N; ++i) lcnt += rng.generate() < mb;
    (lcnt * 2 < N ? lb : ub) = mb;
  }
  
  cout << lb << endl;
  
  return 0;
}
0