結果

問題 No.919 You Are A Project Manager
ユーザー risujirohrisujiroh
提出日時 2019-10-25 22:30:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 94 ms / 3,000 ms
コード長 3,496 bytes
コンパイル時間 1,787 ms
コンパイル使用メモリ 179,884 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 00:56:20
合計ジャッジ時間 5,822 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 15 ms
4,380 KB
testcase_05 AC 16 ms
4,384 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 34 ms
4,380 KB
testcase_08 AC 9 ms
4,380 KB
testcase_09 AC 7 ms
4,380 KB
testcase_10 AC 12 ms
4,384 KB
testcase_11 AC 11 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 14 ms
4,384 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 5 ms
4,376 KB
testcase_16 AC 20 ms
4,380 KB
testcase_17 AC 68 ms
4,376 KB
testcase_18 AC 67 ms
4,380 KB
testcase_19 AC 68 ms
4,380 KB
testcase_20 AC 85 ms
4,376 KB
testcase_21 AC 68 ms
4,376 KB
testcase_22 AC 37 ms
4,380 KB
testcase_23 AC 37 ms
4,380 KB
testcase_24 AC 39 ms
4,384 KB
testcase_25 AC 37 ms
4,380 KB
testcase_26 AC 85 ms
4,380 KB
testcase_27 AC 73 ms
4,384 KB
testcase_28 AC 91 ms
4,380 KB
testcase_29 AC 69 ms
4,384 KB
testcase_30 AC 68 ms
4,376 KB
testcase_31 AC 69 ms
4,376 KB
testcase_32 AC 69 ms
4,376 KB
testcase_33 AC 41 ms
4,380 KB
testcase_34 AC 41 ms
4,380 KB
testcase_35 AC 93 ms
4,380 KB
testcase_36 AC 94 ms
4,380 KB
testcase_37 AC 93 ms
4,376 KB
testcase_38 AC 93 ms
4,384 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 5 ms
4,384 KB
testcase_41 AC 2 ms
4,384 KB
testcase_42 AC 3 ms
4,380 KB
testcase_43 AC 4 ms
4,376 KB
testcase_44 AC 7 ms
4,380 KB
testcase_45 AC 3 ms
4,384 KB
testcase_46 AC 6 ms
4,380 KB
testcase_47 AC 38 ms
4,380 KB
testcase_48 AC 37 ms
4,380 KB
testcase_49 AC 40 ms
4,380 KB
testcase_50 AC 38 ms
4,376 KB
testcase_51 AC 35 ms
4,376 KB
testcase_52 AC 27 ms
4,376 KB
testcase_53 AC 34 ms
4,376 KB
testcase_54 AC 5 ms
4,380 KB
testcase_55 AC 1 ms
4,380 KB
testcase_56 AC 2 ms
4,376 KB
testcase_57 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

#pragma GCC target ("avx")
struct Bitvector {
  using T = uint32_t;
  static constexpr int W = 32;
  static int popcnt(T x) { return __builtin_popcount(x); }

  const int n;
  V<T> b;
  V<> c;
  Bitvector(int _n) : n(_n), b(n / W + 1), c(n / W + 1) {}
  void set(int i) { b[i / W] |= (T)1 << i % W; }
  void build() { for (int i = 0; i < n / W; ++i) c[i + 1] = c[i] + popcnt(b[i]); }
  bool operator[](int i) const { return b[i / W] >> i % W & 1; }
  int rank(int i) const { return c[i / W] + popcnt(b[i / W] & ~(~(T)0 << i % W)); }
  int rank(bool v, int i) const { return v ? rank(i) : i - rank(i); }
};
template<class T> struct WaveletMatrix {
  const int n, h;
  V<Bitvector> b;
  V<> z;
  template<class Itr> WaveletMatrix(Itr first, Itr last) :
    n(distance(first, last)), h(__lg(2 * *max_element(first, last) + 1)), b(h, Bitvector(n)), z(h) {
    assert(*min_element(first, last) >= 0);
    V<T> a(first, last), na(n);
    for (int j = 0; j < h; ++j) {
      for (int i = 0; i < n; ++i) {
        if (a[i] >> h + ~j & 1) b[j].set(i);
        else ++z[j];
      }
      b[j].build();
      int p = 0, q = z[j];
      for (int i = 0; i < n; ++i) (b[j][i] ? na[q++] : na[p++]) = a[i];
      swap(a, na);
    }
  }
  T operator[](int i) const {
    T res = 0;
    for (int j = 0; j < h; ++j) {
      T v = b[j][i];
      res |= v << h + ~j;
      i = v * z[j] + b[j].rank(v, i);
    }
    return res;
  }
  int rank(int l, int r, T x) const {
    if (x < 0 or x >= (T)1 << h) return 0;
    for (int j = 0; j < h; ++j) {
      int v = x >> h + ~j & 1;
      l = v * z[j] + b[j].rank(v, l);
      r = v * z[j] + b[j].rank(v, r);
    }
    return r - l;
  }
  T kth(int l, int r, int k) const {
    assert(0 <= k and k < r - l);
    T res = 0;
    for (int j = 0; j < h; ++j) {
      int p = b[j].rank(0, l), q = b[j].rank(0, r);
      T v = k >= q - p;
      k -= v * (q - p);
      res |= v << h + ~j;
      l = v * z[j] + (v ? l - p : p);
      r = v * z[j] + (v ? r - q : q);
    }
    return res;
  }
  T rkth(int l, int r, int k) const { return kth(l, r, r - l + ~k); }
  int cnt(int l, int r, T x) const {
    if ((x = max<T>(x, 0)) >= (T)1 << h) return 0;
    int res = 0;
    for (int j = 0; j < h; ++j) {
      int p = b[j].rank(1, l), q = b[j].rank(1, r);
      int v = x >> h + ~j & 1;
      res += !v * (q - p);
      l = v * z[j] + (v ? p : l - p);
      r = v * z[j] + (v ? q : r - q);
    }
    return res + r - l;
  }
  int cnt(int l, int r, T x, T y) const { return cnt(l, r, x) - cnt(l, r, y); }
};

int main() {
  constexpr int offset = 1e9;

  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> a(n); for (auto&& e : a) cin >> e, e += offset;
  WaveletMatrix<int> wm(begin(a), end(a));
  lint res = 0;
  for (int k = 1; k <= n; ++k) {
    V<lint> l{0}, r{0};
    for (int i = 0; i + k <= n; i += k) {
      l.push_back(wm.kth(i, i + k, (k - 1) / 2) - offset);
      r.push_back(wm.kth(n - i - k, n - i, (k - 1) / 2) - offset);
    }
    int m = l.size();
    for (int i = 0; i < m - 1; ++i) {
      l[i + 1] += l[i];
      r[i + 1] += r[i];
    }
    for (int i = 0; i < m - 1; ++i) {
      r[i + 1] = max(r[i + 1], r[i]);
    }
    for (int i = 0; i < m; ++i) {
      int j = n / k - i;
      if (j < 0) continue;
      res = max(res, k * (l[i] + r[j]));
    }
  }
  cout << res << '\n';
}
0