結果

問題 No.919 You Are A Project Manager
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-10-25 23:13:59
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 79 ms / 3,000 ms
コード長 3,895 bytes
コンパイル時間 865 ms
コンパイル使用メモリ 114,312 KB
実行使用メモリ 12,560 KB
最終ジャッジ日時 2023-09-04 03:15:53
合計ジャッジ時間 3,936 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
7,236 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 28 ms
6,484 KB
testcase_08 AC 7 ms
4,380 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 10 ms
4,384 KB
testcase_11 AC 9 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 11 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 15 ms
5,156 KB
testcase_17 AC 14 ms
6,948 KB
testcase_18 AC 12 ms
5,924 KB
testcase_19 AC 15 ms
6,756 KB
testcase_20 AC 72 ms
11,280 KB
testcase_21 AC 14 ms
5,960 KB
testcase_22 AC 31 ms
6,728 KB
testcase_23 AC 30 ms
6,760 KB
testcase_24 AC 33 ms
6,748 KB
testcase_25 AC 31 ms
6,672 KB
testcase_26 AC 68 ms
10,708 KB
testcase_27 AC 58 ms
7,672 KB
testcase_28 AC 76 ms
12,560 KB
testcase_29 AC 14 ms
5,440 KB
testcase_30 AC 13 ms
6,568 KB
testcase_31 AC 14 ms
6,684 KB
testcase_32 AC 14 ms
6,688 KB
testcase_33 AC 33 ms
7,060 KB
testcase_34 AC 33 ms
7,020 KB
testcase_35 AC 78 ms
11,092 KB
testcase_36 AC 78 ms
11,368 KB
testcase_37 AC 77 ms
10,728 KB
testcase_38 AC 79 ms
11,260 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 4 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 3 ms
4,384 KB
testcase_44 AC 5 ms
4,380 KB
testcase_45 AC 3 ms
4,376 KB
testcase_46 AC 5 ms
4,376 KB
testcase_47 AC 30 ms
6,980 KB
testcase_48 AC 31 ms
7,276 KB
testcase_49 AC 32 ms
6,820 KB
testcase_50 AC 30 ms
6,792 KB
testcase_51 AC 28 ms
6,788 KB
testcase_52 AC 21 ms
6,216 KB
testcase_53 AC 28 ms
6,956 KB
testcase_54 AC 4 ms
4,380 KB
testcase_55 AC 2 ms
4,380 KB
testcase_56 AC 1 ms
4,376 KB
testcase_57 AC 1 ms
4,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }




void main() {
  try {
    for (; ; ) {
      const N = readInt();
      auto A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt();
      }
      
      const xs = A.dup.sort.uniq.array;
      const asLen = cast(int)(xs.length);
      
      int V;
      int[] l, r;
      int[] sum;
      int node() {
        l ~= 0;
        r ~= 0;
        sum ~= 0;
        return V++;
      }
      
      int segN;
      for (segN = 1; segN < asLen; segN <<= 1) {}
      auto seg = iota(segN << 1).array;
      V = segN << 1;
      l = new int[V];
      r = new int[V];
      sum = new int[V];
      foreach_reverse (a; 1 .. segN) {
        l[a] = a << 1;
        r[a] = a << 1 | 1;
      }
      
      // persistent
      auto roots = new int[N + 1];
      roots[0] = 0;
      foreach (i; 0 .. N) {
        // insert A[i]
        int a = xs.lowerBound(A[i]);
        a += segN;
        const old = seg[a];
        seg[a] = node();
        sum[seg[a]] = sum[old] + 1;
        for (; a >>= 1; ) {
          seg[a] = node();
          l[seg[a]] = seg[a << 1];
          r[seg[a]] = seg[a << 1 | 1];
          sum[seg[a]] = sum[l[seg[a]]] + sum[r[seg[a]]];
        }
        roots[i + 1] = seg[1];
      }
      debug {
        writeln("l = ", l);
        writeln("r = ", r);
        writeln("sum = ", sum);
        writeln("roots = ", roots);
      }
      
      int getMedian(int i, int j) {
        // min x s.t. # (< x) >= (j - i + 1) / 2
        int u = roots[i], v = roots[j];
        int pos;
        int s;
        for (int w = segN; w >>= 1; ) {
          if (s + (sum[l[v]] - sum[l[u]]) >= (j - i + 1) / 2) {
            u = l[u];
            v = l[v];
          } else {
            pos += w;
            s += (sum[l[v]] - sum[l[u]]);
            u = r[u];
            v = r[v];
          }
        }
        debug {
          writefln("median [%s, %s) = xs[%s]", i, j, pos);
        }
        return xs[pos];
      }
      
      long ans;
      foreach (k; 1 .. N + 1) {
        auto ls = new long[N / k + 1];
        foreach (e; 0 .. N / k) {
          ls[e + 1] = ls[e] + getMedian(k * e, k * (e + 1));
        }
        auto rs = new long[N / k + 1];
        foreach (e; 0 .. N / k) {
          rs[e + 1] = rs[e] + getMedian(N - k * (e + 1), N - k * e);
        }
        debug {
          writeln("k = ", k);
          writeln("  ls = ", ls);
          writeln("  rs = ", rs);
        }
        foreach (e; 0 .. N / k) {
          chmax(ls[e + 1], ls[e]);
        }
        long mx;
        foreach (e; 0 .. N / k + 1) {
          chmax(mx, ls[N / k - e] + rs[e]);
        }
        debug {
          writeln("  mx = ", mx);
        }
        chmax(ans, k * mx);
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}
0